mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
WorldUtils mostly ported
This commit is contained in:
parent
42affe942f
commit
9916db2991
4 changed files with 84 additions and 90 deletions
|
@ -1,6 +1,6 @@
|
||||||
package de.ellpeck.actuallyadditions.common.tile;
|
package de.ellpeck.actuallyadditions.common.tile;
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraftforge.energy.EnergyStorage;
|
import net.minecraftforge.energy.EnergyStorage;
|
||||||
|
|
||||||
public class CustomEnergyStorage extends EnergyStorage {
|
public class CustomEnergyStorage extends EnergyStorage {
|
||||||
|
@ -58,12 +58,12 @@ public class CustomEnergyStorage extends EnergyStorage {
|
||||||
return energyExtracted;
|
return energyExtracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound compound) {
|
public void readFromNBT(CompoundNBT compound) {
|
||||||
this.setEnergyStored(compound.getInteger("Energy"));
|
this.setEnergyStored(compound.getInt("Energy"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound compound) {
|
public void writeToNBT(CompoundNBT compound) {
|
||||||
compound.setInteger("Energy", this.getEnergyStored());
|
compound.putInt("Energy", this.getEnergyStored());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnergyStored(int energy) {
|
public void setEnergyStored(int energy) {
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package de.ellpeck.actuallyadditions.common.tile;
|
package de.ellpeck.actuallyadditions.common.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.common.blocks.InitBlocks;
|
import de.ellpeck.actuallyadditions.common.blocks.InitBlocks;
|
||||||
import de.ellpeck.actuallyadditions.common.blocks.metalists.TheMiscBlocks;
|
|
||||||
import de.ellpeck.actuallyadditions.common.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.common.util.WorldUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
|
|
||||||
public class TileEntityLavaFactoryController extends TileEntityBase implements IEnergyDisplay {
|
public class TileEntityLavaFactoryController extends TileEntityBase implements IEnergyDisplay {
|
||||||
|
|
||||||
|
@ -26,20 +25,20 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
public void writeSyncableNBT(CompoundNBT compound, NBTType type) {
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
this.storage.writeToNBT(compound);
|
this.storage.writeToNBT(compound);
|
||||||
if (type != NBTType.SAVE_BLOCK) {
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
compound.setInteger("WorkTime", this.currentWorkTime);
|
compound.putInt("WorkTime", this.currentWorkTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
public void readSyncableNBT(CompoundNBT compound, NBTType type) {
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
this.storage.readFromNBT(compound);
|
this.storage.readFromNBT(compound);
|
||||||
if (type != NBTType.SAVE_BLOCK) {
|
if (type != NBTType.SAVE_BLOCK) {
|
||||||
this.currentWorkTime = compound.getInteger("WorkTime");
|
this.currentWorkTime = compound.getInt("WorkTime");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,12 +67,12 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I
|
||||||
BlockPos thisPos = this.pos;
|
BlockPos thisPos = this.pos;
|
||||||
BlockPos[] positions = new BlockPos[] { thisPos.add(1, 1, 0), thisPos.add(-1, 1, 0), thisPos.add(0, 1, 1), thisPos.add(0, 1, -1) };
|
BlockPos[] positions = new BlockPos[] { thisPos.add(1, 1, 0), thisPos.add(-1, 1, 0), thisPos.add(0, 1, 1), thisPos.add(0, 1, -1) };
|
||||||
|
|
||||||
if (WorldUtil.hasBlocksInPlacesGiven(positions, InitBlocks.blockMisc, TheMiscBlocks.LAVA_FACTORY_CASE.ordinal(), this.world)) {
|
if (WorldUtil.hasBlocksInPlacesGiven(positions, InitBlocks.blockMisc.get(), this.world)) {
|
||||||
BlockPos pos = thisPos.up();
|
BlockPos pos = thisPos.up();
|
||||||
IBlockState state = this.world.getBlockState(pos);
|
BlockState state = this.world.getBlockState(pos);
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (block == Blocks.LAVA || block == Blocks.FLOWING_LAVA) { return HAS_LAVA; }
|
if (block == Blocks.LAVA) { return HAS_LAVA; }
|
||||||
if (block == null || this.world.isAirBlock(pos)) { return HAS_AIR; }
|
if (this.world.isAirBlock(pos)) { return HAS_AIR; }
|
||||||
}
|
}
|
||||||
return NOT_MULTI;
|
return NOT_MULTI;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +88,7 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
public LazyOptional<CustomEnergyStorage> getEnergyStorage(Direction facing) {
|
||||||
return this.storage;
|
return LazyOptional.of(() -> this.storage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.network.EnumPacketDirection;
|
||||||
import net.minecraft.network.NetHandlerPlayServer;
|
import net.minecraft.network.NetHandlerPlayServer;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
|
import net.minecraft.network.play.ServerPlayNetHandler;
|
||||||
import net.minecraft.network.play.client.CPacketAnimation;
|
import net.minecraft.network.play.client.CPacketAnimation;
|
||||||
import net.minecraft.network.play.client.CPacketChatMessage;
|
import net.minecraft.network.play.client.CPacketChatMessage;
|
||||||
import net.minecraft.network.play.client.CPacketClickWindow;
|
import net.minecraft.network.play.client.CPacketClickWindow;
|
||||||
|
@ -40,7 +41,7 @@ import net.minecraft.network.play.server.SPacketPlayerPosLook.EnumFlags;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
import net.minecraftforge.common.util.FakePlayer;
|
||||||
|
|
||||||
public class NetHandlerSpaghettiServer extends NetHandlerPlayServer {
|
public class NetHandlerSpaghettiServer extends ServerPlayNetHandler {
|
||||||
|
|
||||||
public NetHandlerSpaghettiServer(FakePlayer player) {
|
public NetHandlerSpaghettiServer(FakePlayer player) {
|
||||||
super(null, new NetworkManager(EnumPacketDirection.CLIENTBOUND), player);
|
super(null, new NetworkManager(EnumPacketDirection.CLIENTBOUND), player);
|
||||||
|
|
|
@ -7,10 +7,13 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.entity.item.ItemEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.network.play.server.SChangeBlockPacket;
|
||||||
|
import net.minecraft.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
|
@ -20,13 +23,13 @@ import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.server.ServerWorld;
|
||||||
import net.minecraftforge.common.ForgeHooks;
|
import net.minecraftforge.common.ForgeHooks;
|
||||||
import net.minecraftforge.common.IPlantable;
|
import net.minecraftforge.common.IPlantable;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
import net.minecraftforge.common.util.FakePlayer;
|
||||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||||
import net.minecraftforge.energy.CapabilityEnergy;
|
import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
|
||||||
import net.minecraftforge.event.ForgeEventFactory;
|
import net.minecraftforge.event.ForgeEventFactory;
|
||||||
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
|
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
@ -64,24 +67,24 @@ public final class WorldUtil {
|
||||||
|
|
||||||
if (ActuallyAdditions.commonCapsLoaded) {
|
if (ActuallyAdditions.commonCapsLoaded) {
|
||||||
Object handler = extractWrapper.getSlotlessHandler();
|
Object handler = extractWrapper.getSlotlessHandler();
|
||||||
if (handler instanceof ISlotlessItemHandler) {
|
// if (handler instanceof ISlotlessItemHandler) {
|
||||||
ISlotlessItemHandler slotless = (ISlotlessItemHandler) handler;
|
// ISlotlessItemHandler slotless = (ISlotlessItemHandler) handler;
|
||||||
|
//
|
||||||
if (filter == null || !filter.needsCheck()) {
|
// if (filter == null || !filter.needsCheck()) {
|
||||||
extracted = slotless.extractItem(maxExtract, simulate);
|
// extracted = slotless.extractItem(maxExtract, simulate);
|
||||||
return extracted;
|
// return extracted;
|
||||||
} else {
|
// } else {
|
||||||
ItemStack would = slotless.extractItem(maxExtract, true);
|
// ItemStack would = slotless.extractItem(maxExtract, true);
|
||||||
if (filter.check(would)) {
|
// if (filter.check(would)) {
|
||||||
if (simulate) {
|
// if (simulate) {
|
||||||
extracted = would;
|
// extracted = would;
|
||||||
} else {
|
// } else {
|
||||||
extracted = slotless.extractItem(maxExtract, false);
|
// extracted = slotless.extractItem(maxExtract, false);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
//Leave the possibility to fall back to vanilla when there is a filter
|
// //Leave the possibility to fall back to vanilla when there is a filter
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StackUtil.isValid(extracted)) {
|
if (!StackUtil.isValid(extracted)) {
|
||||||
|
@ -105,30 +108,23 @@ public final class WorldUtil {
|
||||||
public static void doEnergyInteraction(TileEntity tileFrom, TileEntity tileTo, Direction sideTo, int maxTransfer) {
|
public static void doEnergyInteraction(TileEntity tileFrom, TileEntity tileTo, Direction sideTo, int maxTransfer) {
|
||||||
if (maxTransfer > 0) {
|
if (maxTransfer > 0) {
|
||||||
Direction opp = sideTo == null ? null : sideTo.getOpposite();
|
Direction opp = sideTo == null ? null : sideTo.getOpposite();
|
||||||
IEnergyStorage handlerFrom = tileFrom.getCapability(CapabilityEnergy.ENERGY, sideTo);
|
tileFrom.getCapability(CapabilityEnergy.ENERGY, sideTo).ifPresent(handlerFrom -> tileTo.getCapability(CapabilityEnergy.ENERGY, opp).ifPresent(handlerTo -> {
|
||||||
IEnergyStorage handlerTo = tileTo.getCapability(CapabilityEnergy.ENERGY, opp);
|
|
||||||
if (handlerFrom != null && handlerTo != null) {
|
|
||||||
int drain = handlerFrom.extractEnergy(maxTransfer, true);
|
int drain = handlerFrom.extractEnergy(maxTransfer, true);
|
||||||
if (drain > 0) {
|
if (drain > 0) {
|
||||||
int filled = handlerTo.receiveEnergy(drain, false);
|
int filled = handlerTo.receiveEnergy(drain, false);
|
||||||
handlerFrom.extractEnergy(filled, false);
|
handlerFrom.extractEnergy(filled, false);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doFluidInteraction(TileEntity tileFrom, TileEntity tileTo, Direction sideTo, int maxTransfer) {
|
public static void doFluidInteraction(TileEntity tileFrom, TileEntity tileTo, Direction sideTo, int maxTransfer) {
|
||||||
if (maxTransfer > 0) {
|
if (maxTransfer > 0) {
|
||||||
if (tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())) {
|
tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo).ifPresent(handlerFrom -> tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite()).ifPresent(handlerTo -> {
|
||||||
IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo);
|
FluidStack drain = handlerFrom.drain(maxTransfer, IFluidHandler.FluidAction.SIMULATE);
|
||||||
IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite());
|
int filled = handlerTo.fill(drain.copy(), IFluidHandler.FluidAction.EXECUTE);
|
||||||
FluidStack drain = handlerFrom.drain(maxTransfer, false);
|
handlerFrom.drain(filled, IFluidHandler.FluidAction.EXECUTE);
|
||||||
if (drain != null) {
|
}));
|
||||||
int filled = handlerTo.fill(drain.copy(), true);
|
|
||||||
handlerFrom.drain(filled, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,24 +133,22 @@ public final class WorldUtil {
|
||||||
*
|
*
|
||||||
* @param positions The Positions, an array of {x, y, z} arrays containing Positions
|
* @param positions The Positions, an array of {x, y, z} arrays containing Positions
|
||||||
* @param block The Block
|
* @param block The Block
|
||||||
* @param meta The Meta
|
|
||||||
* @param world The World
|
* @param world The World
|
||||||
* @return Is every block present?
|
* @return Is every block present?
|
||||||
*/
|
*/
|
||||||
public static boolean hasBlocksInPlacesGiven(BlockPos[] positions, Block block, int meta, World world) {
|
public static boolean hasBlocksInPlacesGiven(BlockPos[] positions, Block block, World world) {
|
||||||
for (BlockPos pos : positions) {
|
for (BlockPos pos : positions) {
|
||||||
IBlockState state = world.getBlockState(pos);
|
BlockState state = world.getBlockState(pos);
|
||||||
if (!(state.getBlock() == block && block.getMetaFromState(state) == meta)) { return false; }
|
if (!(state.getBlock() == block)) { return false; }
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack useItemAtSide(Direction side, World world, BlockPos pos, ItemStack stack) {
|
public static ItemStack useItemAtSide(Direction side, World world, BlockPos pos, ItemStack stack) {
|
||||||
if (world instanceof WorldServer && StackUtil.isValid(stack) && pos != null) {
|
if (world instanceof ServerWorld && StackUtil.isValid(stack) && pos != null) {
|
||||||
BlockPos offsetPos = pos.offset(side);
|
BlockPos offsetPos = pos.offset(side);
|
||||||
IBlockState state = world.getBlockState(offsetPos);
|
BlockState state = world.getBlockState(offsetPos);
|
||||||
Block block = state.getBlock();
|
boolean replaceable = state.getMaterial().isReplaceable();
|
||||||
boolean replaceable = block.isReplaceable(world, offsetPos);
|
|
||||||
|
|
||||||
//Redstone
|
//Redstone
|
||||||
if (replaceable && stack.getItem() == Items.REDSTONE) {
|
if (replaceable && stack.getItem() == Items.REDSTONE) {
|
||||||
|
@ -164,23 +158,23 @@ public final class WorldUtil {
|
||||||
|
|
||||||
//Plants
|
//Plants
|
||||||
if (replaceable && stack.getItem() instanceof IPlantable) {
|
if (replaceable && stack.getItem() instanceof IPlantable) {
|
||||||
if (((IPlantable) stack.getItem()).getPlant(world, offsetPos).getBlock().canPlaceBlockAt(world, offsetPos)) {
|
if (((IPlantable) stack.getItem()).getPlant(world, offsetPos).isValidPosition(world, offsetPos)) {
|
||||||
if (world.setBlockState(offsetPos, ((IPlantable) stack.getItem()).getPlant(world, offsetPos), 2)) return StackUtil.shrink(stack, 1);
|
if (world.setBlockState(offsetPos, ((IPlantable) stack.getItem()).getPlant(world, offsetPos), 2)) return StackUtil.shrink(stack, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Everything else
|
//Everything else
|
||||||
try {
|
try {
|
||||||
FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer) world);
|
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerWorld) world);
|
||||||
if (fake.connection == null) fake.connection = new NetHandlerSpaghettiServer(fake);
|
if (fake.connection == null) fake.connection = new NetHandlerSpaghettiServer(fake);
|
||||||
ItemStack heldBefore = fake.getHeldItemMainhand();
|
ItemStack heldBefore = fake.getHeldItemMainhand();
|
||||||
setHandItemWithoutAnnoyingSound(fake, EnumHand.MAIN_HAND, stack.copy());
|
setHandItemWithoutAnnoyingSound(fake, Hand.MAIN_HAND, stack.copy());
|
||||||
fake.interactionManager.processRightClickBlock(fake, world, fake.getHeldItemMainhand(), EnumHand.MAIN_HAND, offsetPos, side.getOpposite(), 0.5F, 0.5F, 0.5F);
|
fake.interactionManager.processRightClick(fake, world, fake.getHeldItemMainhand(), Hand.MAIN_HAND);
|
||||||
ItemStack result = fake.getHeldItem(EnumHand.MAIN_HAND);
|
ItemStack result = fake.getHeldItem(Hand.MAIN_HAND);
|
||||||
setHandItemWithoutAnnoyingSound(fake, EnumHand.MAIN_HAND, heldBefore);
|
setHandItemWithoutAnnoyingSound(fake, Hand.MAIN_HAND, heldBefore);
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ActuallyAdditions.LOGGER.error("Something that places Blocks at " + offsetPos.getX() + ", " + offsetPos.getY() + ", " + offsetPos.getZ() + " in World " + world.provider.getDimension() + " threw an Exception! Don't let that happen again!", e);
|
ActuallyAdditions.LOGGER.error("Something that places Blocks at " + offsetPos.getX() + ", " + offsetPos.getY() + ", " + offsetPos.getZ() + " in World " + world.getDimension() + " threw an Exception! Don't let that happen again!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -189,12 +183,10 @@ public final class WorldUtil {
|
||||||
public static boolean dropItemAtSide(Direction side, World world, BlockPos pos, ItemStack stack) {
|
public static boolean dropItemAtSide(Direction side, World world, BlockPos pos, ItemStack stack) {
|
||||||
BlockPos coords = pos.offset(side);
|
BlockPos coords = pos.offset(side);
|
||||||
if (world.isBlockLoaded(coords)) {
|
if (world.isBlockLoaded(coords)) {
|
||||||
EntityItem item = new EntityItem(world, coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, stack);
|
ItemEntity item = new ItemEntity(world, coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, stack);
|
||||||
item.motionX = 0;
|
item.setMotion(0, 0, 0);
|
||||||
item.motionY = 0;
|
|
||||||
item.motionZ = 0;
|
|
||||||
|
|
||||||
return world.spawnEntity(item);
|
return world.addEntity(item);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -216,8 +208,8 @@ public final class WorldUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Direction getDirectionByPistonRotation(IBlockState state) {
|
public static Direction getDirectionByPistonRotation(BlockState state) {
|
||||||
return state.getValue(BlockDirectional.FACING);
|
return state.get(BlockStateProperties.FACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Material> getMaterialsAround(World world, BlockPos pos) {
|
public static ArrayList<Material> getMaterialsAround(World world, BlockPos pos) {
|
||||||
|
@ -229,16 +221,18 @@ public final class WorldUtil {
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RayTraceResult getNearestPositionWithAir(World world, EntityPlayer player, int reach) {
|
public static RayTraceResult getNearestPositionWithAir(World world, PlayerEntity player, int reach) {
|
||||||
return getMovingObjectPosWithReachDistance(world, player, reach, false, false, true);
|
return getMovingObjectPosWithReachDistance(world, player, reach, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RayTraceResult getMovingObjectPosWithReachDistance(World world, EntityPlayer player, double distance, boolean p1, boolean p2, boolean p3) {
|
// todo: migrate to standard rayTrace
|
||||||
|
@Deprecated
|
||||||
|
private static RayTraceResult getMovingObjectPosWithReachDistance(World world, PlayerEntity player, double distance, boolean p1, boolean p2, boolean p3) {
|
||||||
float f = player.rotationPitch;
|
float f = player.rotationPitch;
|
||||||
float f1 = player.rotationYaw;
|
float f1 = player.rotationYaw;
|
||||||
double d0 = player.posX;
|
double d0 = player.getPosX();
|
||||||
double d1 = player.posY + player.getEyeHeight();
|
double d1 = player.getPosY() + player.getEyeHeight();
|
||||||
double d2 = player.posZ;
|
double d2 = player.getPosZ();
|
||||||
Vec3d vec3 = new Vec3d(d0, d1, d2);
|
Vec3d vec3 = new Vec3d(d0, d1, d2);
|
||||||
float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI);
|
float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI);
|
||||||
float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI);
|
float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI);
|
||||||
|
@ -247,15 +241,15 @@ public final class WorldUtil {
|
||||||
float f6 = f3 * f4;
|
float f6 = f3 * f4;
|
||||||
float f7 = f2 * f4;
|
float f7 = f2 * f4;
|
||||||
Vec3d vec31 = vec3.add(f6 * distance, f5 * distance, f7 * distance);
|
Vec3d vec31 = vec3.add(f6 * distance, f5 * distance, f7 * distance);
|
||||||
return world.rayTraceBlocks(vec3, vec31, p1, p2, p3);
|
return null; // world.rayTraceBlocks(vec3, vec31, p1, p2, p3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, PlayerEntity player) {
|
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, PlayerEntity player) {
|
||||||
return getNearestBlockWithDefaultReachDistance(world, player, false, true, false);
|
return getNearestBlockWithDefaultReachDistance(world, player, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, EntityPlayer player, boolean stopOnLiquids, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) {
|
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, PlayerEntity player, boolean stopOnLiquids, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) {
|
||||||
return getMovingObjectPosWithReachDistance(world, player, player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue(), stopOnLiquids, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
|
return getMovingObjectPosWithReachDistance(world, player, player.getAttribute(PlayerEntity.REACH_DISTANCE).getValue(), stopOnLiquids, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHandItemWithoutAnnoyingSound(PlayerEntity player, Hand hand, ItemStack stack) {
|
public static void setHandItemWithoutAnnoyingSound(PlayerEntity player, Hand hand, ItemStack stack) {
|
||||||
|
@ -268,11 +262,11 @@ public final class WorldUtil {
|
||||||
|
|
||||||
//I think something is up with this, but I'm not entirely certain what.
|
//I think something is up with this, but I'm not entirely certain what.
|
||||||
public static float fireFakeHarvestEventsForDropChance(TileEntity caller, NonNullList<ItemStack> drops, World world, BlockPos pos) {
|
public static float fireFakeHarvestEventsForDropChance(TileEntity caller, NonNullList<ItemStack> drops, World world, BlockPos pos) {
|
||||||
if (world instanceof WorldServer) {
|
if (world instanceof ServerWorld) {
|
||||||
FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer) world);
|
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerWorld) world);
|
||||||
BlockPos tePos = caller.getPos();
|
BlockPos tePos = caller.getPos();
|
||||||
fake.setPosition(tePos.getX() + 0.5, tePos.getY() + 0.5, tePos.getZ() + 0.5);
|
fake.setPosition(tePos.getX() + 0.5, tePos.getY() + 0.5, tePos.getZ() + 0.5);
|
||||||
IBlockState state = world.getBlockState(pos);
|
BlockState state = world.getBlockState(pos);
|
||||||
|
|
||||||
BreakEvent event = new BreakEvent(world, pos, state, fake);
|
BreakEvent event = new BreakEvent(world, pos, state, fake);
|
||||||
if (!MinecraftForge.EVENT_BUS.post(event)) { return ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1, false, fake); }
|
if (!MinecraftForge.EVENT_BUS.post(event)) { return ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1, false, fake); }
|
||||||
|
@ -299,7 +293,7 @@ public final class WorldUtil {
|
||||||
|
|
||||||
// send update to client
|
// send update to client
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
((ServerPlayerEntity) player).connection.sendPacket(new SPacketBlockChange(world, pos));
|
((ServerPlayerEntity) player).connection.sendPacket(new SChangeBlockPacket(world, pos));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -321,7 +315,7 @@ public final class WorldUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
// always send block update to client
|
// always send block update to client
|
||||||
((ServerPlayerEntity) player).connection.sendPacket(new SPacketBlockChange(world, pos));
|
((ServerPlayerEntity) player).connection.sendPacket(new SChangeBlockPacket(world, pos));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// client sided handling
|
// client sided handling
|
||||||
|
|
Loading…
Reference in a new issue