下面列出了怎么用net.minecraftforge.common.ForgeHooks的API类实例代码及写法,或者点击链接到github查看源代码。
public static List<Tuple<ItemStack, Integer>> getGrassSeedEntries() {
ArrayList<Tuple<ItemStack, Integer>> result = new ArrayList<>();
try {
Field seedListField = ForgeHooks.class.getDeclaredField("seedList");
seedListField.setAccessible(true);
Class<?> seedEntryClass = Class.forName("net.minecraftforge.common.ForgeHooks$SeedEntry");
Field seedField = seedEntryClass.getDeclaredField("seed");
seedField.setAccessible(true);
List<WeightedRandom.Item> seedList = (List<WeightedRandom.Item>) seedListField.get(null);
for (WeightedRandom.Item seedEntryObject : seedList) {
ItemStack seedStack = (ItemStack) seedField.get(seedEntryObject);
int chanceValue = seedEntryObject.itemWeight;
if (!seedStack.isEmpty())
result.add(new Tuple<>(seedStack, chanceValue));
}
} catch (ReflectiveOperationException exception) {
GTLog.logger.error("Failed to get forge grass seed list", exception);
}
return result;
}
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
NonNullList<ItemStack> remains = ForgeHooks.defaultRecipeGetRemainingItems(inv);
for (int i = 0; i < height * width; i++) {
ItemStack stack = inv.getStackInSlot(i);
NonNullList<Ingredient> matchedIngredients = this.input;
if (matchedIngredients.get(i) instanceof IngredientFluidStack) {
if (!stack.isEmpty()) {
ItemStack copy = stack.copy();
copy.setCount(1);
remains.set(i, copy);
}
IFluidHandlerItem handler = FluidUtil.getFluidHandler(remains.get(i));
if (handler != null) {
FluidStack fluid = ((IngredientFluidStack) matchedIngredients.get(i)).getFluid();
handler.drain(fluid.amount, true);
remains.set(i, handler.getContainer());
}
}
}
return remains;
}
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
NonNullList<ItemStack> remainingItems = ForgeHooks.defaultRecipeGetRemainingItems(inv);
ItemStack sword;
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack.getItem() == Items.GOLDEN_SWORD) {
sword = stack.copy();
sword.setItemDamage(sword.getItemDamage() + 1);
if (sword.getItemDamage() > sword.getMaxDamage()) sword = null;
if (sword != null) {
remainingItems.set(i, sword);
}
break;
}
}
return remainingItems;
}
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
NonNullList<ItemStack> remainingItems = ForgeHooks.defaultRecipeGetRemainingItems(inv);
ItemStack gluestick;
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack.getItem() == Items.SLIME_BALL) {
gluestick = stack.copy();
remainingItems.set(i, gluestick);
break;
}
}
return remainingItems;
}
/**
* Breaks the block as a player, and thus drops the item(s) from it
*/
public static void breakBlockAsPlayer(World world, BlockPos pos, EntityPlayerMP playerMP, ItemStack toolStack)
{
PlayerInteractionManager manager = playerMP.interactionManager;
int exp = ForgeHooks.onBlockBreakEvent(world, manager.getGameType(), playerMP, pos);
if (exp != -1)
{
IBlockState stateExisting = world.getBlockState(pos);
Block blockExisting = stateExisting.getBlock();
blockExisting.onBlockHarvested(world, pos, stateExisting, playerMP);
boolean harvest = blockExisting.removedByPlayer(stateExisting, world, pos, playerMP, true);
if (harvest)
{
blockExisting.onPlayerDestroy(world, pos, stateExisting);
blockExisting.harvestBlock(world, playerMP, pos, stateExisting, world.getTileEntity(pos), toolStack);
}
}
}
private List<ITextComponent> resizeContent(List<String> lines)
{
List<ITextComponent> ret = new ArrayList<ITextComponent>();
for (String line : lines)
{
if (line == null)
{
ret.add(null);
continue;
}
ITextComponent chat = ForgeHooks.newChatWithLinks(line, false);
ret.addAll(GuiUtilRenderComponents.splitText(chat, this.listWidth-8, GuiCustomizeWorld.this.fontRenderer, false, true));
}
return ret;
}
private void selectTool(IBlockState state, OpenModsFakePlayer fakePlayer) {
if (findEffectiveTool) {
final ItemStack optimalTool = effectiveToolCache.getIfPresent(state);
if (optimalTool != null) {
setPlayerTool(fakePlayer, optimalTool);
} else {
for (ItemStack tool : ConfigAccess.probeTools()) {
setPlayerTool(fakePlayer, tool);
if (ForgeHooks.canHarvestBlock(state.getBlock(), fakePlayer, worldObj, blockPos)) {
effectiveToolCache.put(state, tool);
return;
}
}
// default clause - use most universal one
final ItemStack fallbackTool = createToolStack(Items.DIAMOND_PICKAXE);
effectiveToolCache.put(state, fallbackTool);
setPlayerTool(fakePlayer, fallbackTool);
}
} else {
setPlayerTool(fakePlayer, stackToUse);
}
}
public static float getPower(World world, BlockPos position) {
float power = 0;
for (int deltaZ = -1; deltaZ <= 1; ++deltaZ) {
for (int deltaX = -1; deltaX <= 1; ++deltaX) {
if ((deltaZ != 0 || deltaX != 0)
&& world.isAirBlock(position.add(deltaX, 0, deltaZ))
&& world.isAirBlock(position.add(deltaX, 1, deltaZ))) {
power += ForgeHooks.getEnchantPower(world, position.add(deltaX * 2, 0, deltaZ * 2));
power += ForgeHooks.getEnchantPower(world, position.add(deltaX * 2, 1, deltaZ * 2));
if (deltaX != 0 && deltaZ != 0) {
power += ForgeHooks.getEnchantPower(world, position.add(deltaX * 2, 0, deltaZ));
power += ForgeHooks.getEnchantPower(world, position.add(deltaX * 2, 1, deltaZ));
power += ForgeHooks.getEnchantPower(world, position.add(deltaX, 0, deltaZ * 2));
power += ForgeHooks.getEnchantPower(world, position.add(deltaX, 1, deltaZ * 2));
}
}
}
}
return power;
}
@Override
public float getPlayerRelativeBlockHardness(EntityPlayer player, World world, int x, int y, int z)
{
TileEntity te = world.getTileEntity(x, y, z);
TileEntityDisplayPedestal ted = (TileEntityDisplayPedestal)te;
if((ted.ownerUUID.getLeastSignificantBits() == player.getUniqueID().getLeastSignificantBits() &&
ted.ownerUUID.getMostSignificantBits() == player.getUniqueID().getMostSignificantBits()) ||
ted.ownerName.equals(player.getCommandSenderName()) ||
ted.ownerName == null || ted.ownerName.equals("") ||
ted.ownerUUID == null || ted.ownerUUID.equals(new UUID(0,0))) {
float f = this.getBlockHardness(world, x, y, z);
return ForgeHooks.blockStrength(this, player, world, x, y, z);
}
else {
return 0;
}
}
private boolean canBreakExtraBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos, BlockPos refPos) {
if (world.isAirBlock(pos)) {
return false;
}
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (tool.getDestroySpeed(stack, state) <= 1.0F)
return false;
IBlockState refState = world.getBlockState(refPos);
float refStrength = ForgeHooks.blockStrength(refState, player, world, refPos);
float strength = ForgeHooks.blockStrength(state, player, world, pos);
if (!ForgeHooks.canHarvestBlock(block, player, world, pos) || refStrength / strength > 10f) {
return false;
}
if (player.capabilities.isCreativeMode) {
block.onBlockHarvested(world, pos, state, player);
if (block.removedByPlayer(state, world, pos, player, false)) {
block.onBlockDestroyedByPlayer(world, pos, state);
}
// send update to client
if (!world.isRemote) {
if (player instanceof EntityPlayerMP && ((EntityPlayerMP) player).connection != null) {
((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));
}
}
return false;
}
return true;
}
public boolean performRecipe(EntityPlayer player) {
this.lastTickChecked = -1L;
if (!checkRecipeValid()) {
return false;
}
if (!consumeRecipeItems(false)) {
this.lastTickChecked = -1L;
return false;
}
ForgeHooks.setCraftingPlayer(player);
NonNullList<ItemStack> remainingItems = recipe.getRemainingItems(inventory);
ForgeHooks.setCraftingPlayer(null);
for (ItemStack itemStack : remainingItems) {
itemStack = itemStack.copy();
ItemStackKey stackKey = new ItemStackKey(itemStack);
int remainingAmount = itemStack.getCount() - itemSourceList.insertItem(stackKey, itemStack.getCount(), false, InsertMode.HIGHEST_PRIORITY);
if (remainingAmount > 0) {
itemStack.setCount(remainingAmount);
player.addItemStackToInventory(itemStack);
if (itemStack.getCount() > 0) {
player.dropItem(itemStack, false, false);
}
}
}
this.lastTickChecked = -1L;
return true;
}
@Override
public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos blockPos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (player.canPlayerEdit(blockPos, facing, stack) && !world.isAirBlock(blockPos)) {
IBlockState blockState = world.getBlockState(blockPos);
if (blockState.getBlock() == Blocks.GRASS || blockState.getBlock() == Blocks.DIRT) {
if (blockState.getBlock() == Blocks.GRASS && player.isSneaking()) {
if (GTUtility.doDamageItem(stack, this.cost, false)) {
if (world.rand.nextInt(3) == 0) {
ItemStack grassSeed = ForgeHooks.getGrassSeed(world.rand, 0);
Block.spawnAsEntity(world, blockPos.up(), grassSeed);
}
world.playSound(null, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.PLAYERS, 1.0F, 1.0F);
world.setBlockState(blockPos, Blocks.DIRT.getDefaultState()
.withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT));
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
} else if (blockState.getBlock() == Blocks.GRASS
|| blockState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT
|| blockState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.COARSE_DIRT) {
if (GTUtility.doDamageItem(stack, this.cost, false)) {
world.playSound(null, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.PLAYERS, 1.0F, 1.0F);
world.setBlockState(blockPos, Blocks.FARMLAND.getDefaultState());
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
}
}
}
return ActionResult.newResult(EnumActionResult.FAIL, stack);
}
@Override
public void setInventorySlotContents(int slotNR, ItemStack itemStack) {
if (itemStack != null && itemStack.getItem() != null && itemStack.getItem().equals(GT_Utility.getIntegratedCircuit(0).getItem())) {
this.Slot = BW_Util.setStackSize(itemStack.copy(),1);
itemStack.stackSize--;
this.tag = this.toBind.getTagCompound();
this.tag.setBoolean("HasChip", true);
this.tag.setByte("ChipConfig", (byte) itemStack.getItemDamage());
this.toBind.setTagCompound(this.tag);
this.Player.inventory.setInventorySlotContents(this.Player.inventory.currentItem, this.toBind);
if (!this.Player.isClientWorld())
MainMod.BW_Network_instance.sendToServer(new CircuitProgrammerPacket(this.Player.worldObj.provider.dimensionId, this.Player.getEntityId(), true, (byte) itemStack.getItemDamage()));
} else if (BW_Util.checkStackAndPrefix(itemStack) && GT_OreDictUnificator.getAssociation(itemStack).mPrefix.equals(OrePrefixes.circuit) && GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial.equals(Materials.Basic)) {
this.Slot = GT_Utility.getIntegratedCircuit(0);
this.Slot.stackSize = 1;
itemStack.stackSize--;
this.tag = this.toBind.getTagCompound();
this.tag.setBoolean("HasChip", true);
this.tag.setByte("ChipConfig", (byte) 0);
this.toBind.setTagCompound(this.tag);
this.Player.inventory.setInventorySlotContents(this.Player.inventory.currentItem, this.toBind);
if (!this.Player.isClientWorld())
MainMod.BW_Network_instance.sendToServer(new CircuitProgrammerPacket(this.Player.worldObj.provider.dimensionId, this.Player.getEntityId(), true, (byte) 0));
}/* else if (GT_Utility.isStackValid(itemStack) && itemStack.getItem() instanceof Circuit_Programmer) {
ForgeHooks.onPlayerTossEvent(Player, itemStack, false);
this.closeInventory();
Player.closeScreen();
}*/ else {
ForgeHooks.onPlayerTossEvent(this.Player, itemStack, false);
this.tag = this.toBind.getTagCompound();
this.tag.setBoolean("HasChip", false);
this.toBind.setTagCompound(this.tag);
this.Player.inventory.setInventorySlotContents(this.Player.inventory.currentItem, this.toBind);
if (!this.Player.isClientWorld())
MainMod.BW_Network_instance.sendToServer(new CircuitProgrammerPacket(this.Player.worldObj.provider.dimensionId, this.Player.getEntityId(), false, (byte) 0));
}
}
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> items = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
getMatch(inv);
int[] amounts = getAmounts(wasMirrored);
for (int col = 0; col < getWidth(); col++)
{
for (int row = 0; row < getHeight(); row++)
{
int amountIndex = col + row * getWidth();
int invIndex = matchX + col + (row + matchY) * inv.getWidth();
int amount = amounts[amountIndex];
if (amount > 0)
{
ItemStack stack = inv.getStackInSlot(invIndex).copy();
stack.setItemDamage(stack.getItemDamage() + amount);
if (stack.getItemDamage() > stack.getMaxDamage())
{
stack = ForgeHooks.getContainerItem(stack);
}
items.set(invIndex, stack);
} else
{
items.set(invIndex, ForgeHooks.getContainerItem(inv.getStackInSlot(invIndex)));
}
}
}
return items;
}
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> items = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
matches(inv, null);
for (int i = 0; i < invSlots.length; i++)
{
int amount = damageAmounts[i];
int invIndex = invSlots[i];
if (amount > 0)
{
ItemStack stack = inv.getStackInSlot(invIndex).copy();
stack.setItemDamage(stack.getItemDamage() + amount);
if (stack.getItemDamage() > stack.getMaxDamage())
{
stack = ForgeHooks.getContainerItem(stack);
}
items.set(invIndex, stack);
} else
{
items.set(invIndex, ForgeHooks.getContainerItem(inv.getStackInSlot(invIndex)));
}
}
return items;
}
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
NonNullList<ItemStack> remainingItems = ForgeHooks.defaultRecipeGetRemainingItems(inv);
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack.getItem() instanceof IPearlSwappable) {
remainingItems.set(i, new ItemStack(stack.getItem()));
}
}
return remainingItems;
}
@Override
public boolean isEffectiveOn(Object... obj) {
if (((obj[1] instanceof ItemStack)) && ((obj[2] instanceof BlockPos)) && ((obj[3] instanceof World))) {
ItemStack stack = (ItemStack) obj[1];
BlockPos pos = (BlockPos) obj[2];
World world = (World) obj[3];
return ForgeHooks.isToolEffective(world, pos, stack);
}
return false;
}
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
if(state.getValue(FILL) > 0 && state.getValue(FILLTYPE) == FillType.Charcoal &&
ForgeHooks.isToolEffective(worldIn, pos, player.getHeldItemMainhand()))
{
Core.giveItem(worldIn, player, pos, new ItemStack(Items.COAL, 1, 1));
worldIn.setBlockState(pos, state.withProperty(FILL, state.getValue(FILL)-1));
}
}
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase player) {
if(EnchantmentHelper.getEnchantmentLevel(DarkEnchantments.impact.effectId, stack) <= 0)
return super.onBlockDestroyed(stack, world, block, x, y, z, player);
if(!player.worldObj.isRemote) {
int meta = world.getBlockMetadata(x, y, z);
if(ForgeHooks.isToolEffective(stack, block, meta)) {
for(int aa = -1; aa <= 1; ++aa) {
for(int bb = -1; bb <= 1; ++bb) {
int xx = 0;
int yy = 0;
int zz = 0;
if(this.side <= 1) {
xx = aa;
zz = bb;
} else if(this.side <= 3) {
xx = aa;
yy = bb;
} else {
zz = aa;
yy = bb;
}
if(!(player instanceof EntityPlayer) || world.canMineBlock((EntityPlayer)player, x + xx, y + yy, z + zz)) {
Block bl = world.getBlock(x + xx, y + yy, z + zz);
meta = world.getBlockMetadata(x + xx, y + yy, z + zz);
if(bl.getBlockHardness(world, x + xx, y + yy, z + zz) >= 0.0F && ForgeHooks.isToolEffective(stack, bl, meta)) {
stack.damageItem(1, player);
BlockUtils.harvestBlock(world, (EntityPlayer)player, x + xx, y + yy, z + zz, true, 2);
}
}
}
}
}
else
return super.onBlockDestroyed(stack, world, block, x, y, z, player);
}
return super.onBlockDestroyed(stack, world, block, x, y, z, player);
}
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase player) {
if(EnchantmentHelper.getEnchantmentLevel(DarkEnchantments.impact.effectId, stack) <= 0)
return super.onBlockDestroyed(stack, world, block, x, y, z, player);
if(!player.worldObj.isRemote) {
int meta = world.getBlockMetadata(x, y, z);
if(ForgeHooks.isToolEffective(stack, block, meta)) {
for(int aa = -1; aa <= 1; ++aa) {
for(int bb = -1; bb <= 1; ++bb) {
int xx = 0;
int yy = 0;
int zz = 0;
if(this.side <= 1) {
xx = aa;
zz = bb;
} else if(this.side <= 3) {
xx = aa;
yy = bb;
} else {
zz = aa;
yy = bb;
}
if(!(player instanceof EntityPlayer) || world.canMineBlock((EntityPlayer)player, x + xx, y + yy, z + zz)) {
Block bl = world.getBlock(x + xx, y + yy, z + zz);
meta = world.getBlockMetadata(x + xx, y + yy, z + zz);
if(bl.getBlockHardness(world, x + xx, y + yy, z + zz) >= 0.0F && ForgeHooks.isToolEffective(stack, bl, meta)) {
stack.damageItem(1, player);
BlockUtils.harvestBlock(world, (EntityPlayer)player, x + xx, y + yy, z + zz, true, 2);
}
}
}
}
}
else
return super.onBlockDestroyed(stack, world, block, x, y, z, player);
}
return super.onBlockDestroyed(stack, world, block, x, y, z, player);
}
@Override
public float getDigSpeed(ItemStack stack, Block block, int meta)
{
if (ForgeHooks.isToolEffective(stack, block, meta) ||
(block.getMaterial() == Config.taintMaterial && block != ForbiddenBlocks.taintLog && block != ForbiddenBlocks.taintPlanks
&& block != ForbiddenBlocks.taintStone))
{
return efficiencyOnProperMaterial;
}
return func_150893_a(stack, block);
}
/**
* Attempts to harvest a block at the given coordinate
*/
@Override
public boolean tryHarvestBlock(int x, int y, int z){
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(theWorld, getGameType(), thisPlayerMP, x, y, z);
if(event.isCanceled()) {
return false;
} else {
ItemStack stack = thisPlayerMP.getCurrentEquippedItem();
if(stack != null && stack.getItem().onBlockStartBreak(stack, x, y, z, thisPlayerMP)) {
return false;
}
Block block = theWorld.getBlock(x, y, z);
int l = theWorld.getBlockMetadata(x, y, z);
theWorld.playAuxSFXAtEntity(thisPlayerMP, 2001, x, y, z, Block.getIdFromBlock(block) + (theWorld.getBlockMetadata(x, y, z) << 12));
boolean flag = false;
ItemStack itemstack = thisPlayerMP.getCurrentEquippedItem();
if(itemstack != null) {
itemstack.func_150999_a(theWorld, block, x, y, z, thisPlayerMP);
if(itemstack.stackSize == 0) {
thisPlayerMP.destroyCurrentEquippedItem();
}
}
if(removeBlock(x, y, z)) {
block.harvestBlock(theWorld, thisPlayerMP, x, y, z, l);
flag = true;
}
// Drop experience
if(!isCreative() && flag && event != null) {
block.dropXpOnBlockBreak(theWorld, x, y, z, event.getExpToDrop());
}
drone.addAir(null, -PneumaticValues.DRONE_USAGE_DIG);
return true;
}
}
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
NonNullList<ItemStack> result = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < result.size(); ++i) {
ItemStack itemstack = inv.getStackInSlot(i);
result.set(i, ForgeHooks.getContainerItem(itemstack));
}
return result;
}
@Override
public boolean canMineBlock(ItemStack stack, IBlockState state, IBlockAccess access, BlockPos pos) {
return ForgeHooks.canToolHarvestBlock(access, pos, stack);
}
@Override
public boolean canMineBlock(ItemStack stack, IBlockState state, IBlockAccess access, BlockPos pos) {
return ForgeHooks.canToolHarvestBlock(access, pos, stack);
}
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
return ForgeHooks.defaultRecipeGetRemainingItems(inv);
}
private void teleport(EntityMinecart cart, MCPos destination){
if(cart instanceof EntityMinecartContainer) {
((EntityMinecartContainer)cart).dropContentsWhenDead = false;
}
int dimensionIn = destination.getDimID();
BlockPos destPos = destination.getPos();
if(!ForgeHooks.onTravelToDimension(cart, destination.getDimID())) return;
MinecraftServer minecraftserver = cart.getServer();
int i = cart.dimension;
WorldServer worldserver = minecraftserver.getWorld(i);
WorldServer worldserver1 = minecraftserver.getWorld(dimensionIn);
cart.dimension = dimensionIn;
/*if (i == 1 && dimensionIn == 1)
{
worldserver1 = minecraftserver.getWorld(0);
this.dimension = 0;
}*/
cart.world.removeEntity(cart);
cart.isDead = false;
BlockPos blockpos = destination.getPos();
/* double moveFactor = worldserver.provider.getMovementFactor() / worldserver1.provider.getMovementFactor();
double d0 = MathHelper.clamp(this.posX * moveFactor, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D);
double d1 = MathHelper.clamp(this.posZ * moveFactor, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D);
double d2 = 8.0D;*/
cart.moveToBlockPosAndAngles(destPos, 90.0F, 0.0F);
/*Teleporter teleporter = worldserver1.getDefaultTeleporter();
teleporter.placeInExistingPortal(this, f);
blockpos = new BlockPos(this);*/
worldserver.updateEntityWithOptionalForce(cart, false);
Entity entity = EntityList.newEntity(cart.getClass(), worldserver1);
if(entity != null) {
copyDataFromOld(entity, cart);
entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw, entity.rotationPitch);
IBlockState state = destination.getLoadedBlockState();
if(state.getBlock() == ModBlocks.TELEPORT_RAIL) { //If the destination is a teleport track, use its rail direction to push the cart the right direction
EnumFacing teleportDir = getTeleportDirection(state);
double speed = 0.2;
entity.motionX = teleportDir.getFrontOffsetX() * speed;
entity.motionY = teleportDir.getFrontOffsetY() * speed;
entity.motionZ = teleportDir.getFrontOffsetZ() * speed;
} else {
entity.motionX = entity.motionY = entity.motionZ = 0;
}
boolean flag = entity.forceSpawn;
entity.forceSpawn = true;
worldserver1.spawnEntity(entity);
entity.forceSpawn = flag;
worldserver1.updateEntityWithOptionalForce(entity, false);
}
cart.isDead = true;
worldserver.resetUpdateEntityTick();
worldserver1.resetUpdateEntityTick();
}
@Override
public void tick()
{
if (world.isRemote)
return;
boolean changes = false;
if (needRefreshRecipe)
{
totalBurnTime = ForgeHooks.getBurnTime(inventory.getStackInSlot(1));
totalCookTime = getSawmillTime(world, inventory.getStackInSlot(0));
needRefreshRecipe = false;
}
if (this.isBurning())
{
--this.remainingBurnTime;
}
if (!this.world.isRemote)
{
ItemStack fuel = this.inventory.getStackInSlot(1);
if (this.isBurning() || !fuel.isEmpty())
{
ChoppingContext ctx = new ChoppingContext(inventory, null, 0, 0, RANDOM);
changes |= ChoppingRecipe.getRecipe(world, ctx).map(choppingRecipe -> {
boolean changes2 = false;
if (!this.isBurning() && this.canWork(ctx, choppingRecipe))
{
this.totalBurnTime = ForgeHooks.getBurnTime(fuel);
this.remainingBurnTime = this.totalBurnTime;
if (this.isBurning())
{
changes2 = true;
if (!fuel.isEmpty())
{
Item item = fuel.getItem();
fuel.shrink(1);
if (fuel.isEmpty())
{
ItemStack containerItem = item.getContainerItem(fuel);
this.inventory.setStackInSlot(1, containerItem);
}
}
}
}
if (this.isBurning() && this.canWork(ctx, choppingRecipe))
{
++this.cookTime;
if (this.totalCookTime == 0)
{
this.totalCookTime = choppingRecipe.getSawingTime();
}
if (this.cookTime >= this.totalCookTime)
{
this.cookTime = 0;
this.totalCookTime = choppingRecipe.getSawingTime();
this.processItem(ctx, choppingRecipe);
changes2 = true;
}
}
else
{
this.cookTime = 0;
}
return changes2;
}).orElse(false);
}
if (!this.isBurning() && this.cookTime > 0)
{
this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.totalCookTime);
}
}
BlockState state = getBlockState();
if (state.get(SawmillBlock.POWERED) != this.isBurning())
{
state = state.with(SawmillBlock.POWERED, this.isBurning());
world.setBlockState(pos, state);
}
if (changes)
{
this.markDirty();
}
}
public final boolean isEffectiveOn(ItemStack stack, BlockPos pos, World world) {
if (ForgeHooks.isToolEffective(world, pos, stack))
return true;
else return isEffectiveOn(stack);
}
public static List<?> getSeeds() {
return getPrivateStaticObject(ForgeHooks.class, "seedList");
}