Port to 1.11

This commit is contained in:
Shadowfacts 2016-11-20 09:36:16 -05:00
parent 122fd9c6c9
commit d1a69c8231
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
8 changed files with 31 additions and 86 deletions

View File

@ -68,7 +68,7 @@ curseforge {
project { project {
id = "246215" id = "246215"
addGameVersion "1.10.2" addGameVersion "1.11"
addGameVersion "Java 8" addGameVersion "Java 8"
mainArtifact(jar) { mainArtifact(jar) {

View File

@ -1,10 +1,10 @@
mod_version = 1.1.1 mod_version = 1.2.0
group = net.shadowfacts group = net.shadowfacts
archivesBaseName = Funnels archivesBaseName = Funnels
mc_version = 1.10.2 mc_version = 1.11
mcp_mappings = snapshot_20160705 mcp_mappings = snapshot_20161120
forge_version = 12.18.0.2007-1.10.0 forge_version = 13.19.0.2153
shadowmc_version = 3.4.0 shadowmc_version = 3.7.0
jei_version = 3.7.3.223 jei_version = 4.0.2.194

View File

@ -16,6 +16,9 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidActionResult;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.shadowfacts.shadowmc.block.BlockTE; import net.shadowfacts.shadowmc.block.BlockTE;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -78,21 +81,19 @@ public class BlockFunnel extends BlockTE<TileEntityFunnel> {
} }
@Override @Override
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
EnumFacing side = facing.getOpposite(); EnumFacing side = facing.getOpposite();
if (side == EnumFacing.UP) side = EnumFacing.DOWN; if (side == EnumFacing.UP) side = EnumFacing.DOWN;
return getDefaultState().withProperty(FACING, side); return getDefaultState().withProperty(FACING, side);
} }
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY) {
if (!player.isSneaking()) { if (!player.isSneaking()) {
TileEntityFunnel te = getTileEntity(world, pos); TileEntityFunnel te = getTileEntity(world, pos);
ItemStack stack = player.getHeldItem(hand);
if (FluidUtils.fillHandlerWithContainer(world, te.tank, player, hand)) { FluidActionResult result = FluidUtil.interactWithFluidHandler(stack, te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.NORTH), player);
te.save(); if (result.isSuccess()) {
return true;
} else if (FluidUtils.fillContainerFromHandler(world, te.tank, player, hand, te.tank.getFluid())) {
te.save(); te.save();
return true; return true;
} }

View File

@ -17,62 +17,6 @@ import net.minecraftforge.fluids.capability.IFluidHandler;
*/ */
public class FluidUtils { public class FluidUtils {
public static boolean fillHandlerWithContainer(World world, IFluidHandler handler, EntityPlayer player, EnumHand hand) {
ItemStack container = player.getHeldItem(hand);
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(container);
if (fluid != null) {
if (handler.fill(fluid, false) == fluid.amount || player.capabilities.isCreativeMode) {
ItemStack returnStack = FluidContainerRegistry.drainFluidContainer(container);
if (world.isRemote) {
return true;
}
if (!player.capabilities.isCreativeMode) {
if (PlayerUtils.disposePlayerItem(player.getHeldItem(hand), returnStack, player, true)) {
player.openContainer.detectAndSendChanges();
((EntityPlayerMP)player).sendContainerToPlayer(player.openContainer);
}
}
handler.fill(fluid, true);
return true;
}
}
return false;
}
public static boolean fillContainerFromHandler(World world, IFluidHandler handler, EntityPlayer player, EnumHand hand, FluidStack tankFluid) {
ItemStack container = player.getHeldItem(hand);
if (FluidContainerRegistry.isEmptyContainer(container)) {
ItemStack returnStack = FluidContainerRegistry.fillFluidContainer(tankFluid, container);
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(returnStack);
if (fluid == null || returnStack == null) {
return false;
}
if (world.isRemote) {
return true;
}
if (!player.capabilities.isCreativeMode) {
if (container.stackSize == 1) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, returnStack);
container.stackSize--;
if (container.stackSize <= 0) {
container = null;
}
} else {
if (PlayerUtils.disposePlayerItem(player.getHeldItem(hand), returnStack, player, true)) {
player.openContainer.detectAndSendChanges();
((EntityPlayerMP) player).sendContainerToPlayer(player.openContainer);
}
}
}
handler.drain(fluid.amount, true);
return true;
}
return false;
}
public static boolean isFluidBlock(World world, BlockPos pos) { public static boolean isFluidBlock(World world, BlockPos pos) {
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockLiquid) { if (state.getBlock() instanceof BlockLiquid) {

View File

@ -13,7 +13,7 @@ import net.minecraftforge.oredict.ShapedOreRecipe;
/** /**
* @author shadowfacts * @author shadowfacts
*/ */
@Mod(modid = Funnels.modId, name = Funnels.name, version = Funnels.version, dependencies = "required-after:shadowmc@[3.4.0,);", acceptedMinecraftVersions = "[1.10.2]", guiFactory = "net.shadowfacts.funnels.GUIFactory") @Mod(modid = Funnels.modId, name = Funnels.name, version = Funnels.version, dependencies = "required-after:shadowmc@[3.4.0,);", guiFactory = "net.shadowfacts.funnels.GUIFactory")
public class Funnels { public class Funnels {
public static final String modId = "Funnels"; public static final String modId = "Funnels";

View File

@ -13,12 +13,12 @@ public class PlayerUtils {
if (entityplayer == null || entityplayer.capabilities.isCreativeMode) { if (entityplayer == null || entityplayer.capabilities.isCreativeMode) {
return true; return true;
} }
if (allowReplace && stack.stackSize <= 1) { if (allowReplace && stack.getCount() <= 1) {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, null); entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, ItemStack.EMPTY);
entityplayer.inventory.addItemStackToInventory(dropStack); entityplayer.inventory.addItemStackToInventory(dropStack);
return true; return true;
} else if (allowDrop) { } else if (allowDrop) {
stack.stackSize -= 1; stack.shrink(1);
if (dropStack != null && !entityplayer.inventory.addItemStackToInventory(dropStack)) { if (dropStack != null && !entityplayer.inventory.addItemStackToInventory(dropStack)) {
entityplayer.dropItem(dropStack, false, true); entityplayer.dropItem(dropStack, false, true);
} }

View File

@ -28,7 +28,7 @@ public class TESRFunnel extends TileEntitySpecialRenderer<TileEntityFunnel> {
renderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); renderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
int color = fluid.getFluid().getColor(fluid); int color = fluid.getFluid().getColor(fluid);
int brightness = Minecraft.getMinecraft().theWorld.getCombinedLight(te.getPos(), fluid.getFluid().getLuminosity()); int brightness = Minecraft.getMinecraft().world.getCombinedLight(te.getPos(), fluid.getFluid().getLuminosity());
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();

View File

@ -31,18 +31,18 @@ public class TileEntityFunnel extends BaseTileEntity implements ITickable {
void save() { void save() {
markDirty(); markDirty();
ShadowMC.network.sendToAllAround(new PacketUpdateTE(this), new NetworkRegistry.TargetPoint(worldObj.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64)); ShadowMC.network.sendToAllAround(new PacketUpdateTE(this), new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64));
} }
@Override @Override
public void update() { public void update() {
if (!worldObj.isRemote) { if (!world.isRemote) {
handlers: handlers:
{ {
// up handler -> tank // up handler -> tank
if (tank.getFluidAmount() < tank.getCapacity()) { if (tank.getFluidAmount() < tank.getCapacity()) {
BlockPos handlerPos = pos.up(); BlockPos handlerPos = pos.up();
TileEntity te = worldObj.getTileEntity(handlerPos); TileEntity te = world.getTileEntity(handlerPos);
if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN)) { if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN); IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN);
tank.fill(handler.drain(tank.getCapacity() - tank.getFluidAmount(), true), true); tank.fill(handler.drain(tank.getCapacity() - tank.getFluidAmount(), true), true);
@ -52,9 +52,9 @@ public class TileEntityFunnel extends BaseTileEntity implements ITickable {
} }
// tank -> front handler // tank -> front handler
if (tank.getFluidAmount() > 0) { if (tank.getFluidAmount() > 0) {
EnumFacing facing = worldObj.getBlockState(pos).getValue(BlockFunnel.FACING); EnumFacing facing = world.getBlockState(pos).getValue(BlockFunnel.FACING);
BlockPos handlerPos = pos.offset(facing); BlockPos handlerPos = pos.offset(facing);
TileEntity te = worldObj.getTileEntity(handlerPos); TileEntity te = world.getTileEntity(handlerPos);
if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite())) { if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite())) {
IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite()); IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite());
tank.drain(handler.fill(tank.drain(20, false), true), true); tank.drain(handler.fill(tank.drain(20, false), true), true);
@ -70,10 +70,10 @@ public class TileEntityFunnel extends BaseTileEntity implements ITickable {
// pickup from world // pickup from world
if (FunnelsConfig.pickupWorldFluids && tank.getFluidAmount() <= tank.getCapacity() - Fluid.BUCKET_VOLUME) { if (FunnelsConfig.pickupWorldFluids && tank.getFluidAmount() <= tank.getCapacity() - Fluid.BUCKET_VOLUME) {
tick = 0; tick = 0;
if (FluidUtils.isFluidBlock(worldObj, pos.up())) { if (FluidUtils.isFluidBlock(world, pos.up())) {
FluidStack toDrain = FluidUtils.drainFluidBlock(worldObj, pos.up(), false); FluidStack toDrain = FluidUtils.drainFluidBlock(world, pos.up(), false);
if (toDrain.amount <= tank.getCapacity() - tank.getFluidAmount()) { if (toDrain.amount <= tank.getCapacity() - tank.getFluidAmount()) {
tank.fill(FluidUtils.drainFluidBlock(worldObj, pos.up(), true), true); tank.fill(FluidUtils.drainFluidBlock(world, pos.up(), true), true);
save(); save();
break world; break world;
} }
@ -84,11 +84,11 @@ public class TileEntityFunnel extends BaseTileEntity implements ITickable {
FluidStack fluid = tank.getFluid(); FluidStack fluid = tank.getFluid();
if (fluid.getFluid().canBePlacedInWorld()) { if (fluid.getFluid().canBePlacedInWorld()) {
Block fluidBlock = fluid.getFluid().getBlock(); Block fluidBlock = fluid.getFluid().getBlock();
BlockPos newPos = pos.offset(worldObj.getBlockState(pos).getValue(BlockFunnel.FACING)); BlockPos newPos = pos.offset(world.getBlockState(pos).getValue(BlockFunnel.FACING));
if (fluidBlock.canPlaceBlockAt(worldObj, newPos)) { if (fluidBlock.canPlaceBlockAt(world, newPos)) {
tank.drain(Fluid.BUCKET_VOLUME, true); tank.drain(Fluid.BUCKET_VOLUME, true);
save(); save();
worldObj.setBlockState(newPos, fluidBlock.getDefaultState()); world.setBlockState(newPos, fluidBlock.getDefaultState());
} }
} }
} }