mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 16:58:34 +01:00
Made the placer be able to apply bonemeal and do some more awesome stuffz
This commit is contained in:
parent
9ed85158e7
commit
7586b7cd56
4 changed files with 24 additions and 25 deletions
|
@ -89,9 +89,9 @@ public class TileEntityBreaker extends TileEntityInventoryBase implements IRedst
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(this.isPlacer && PosUtil.getBlock(coordsBlock, worldObj).isReplaceable(worldObj, coordsBlock)){
|
else if(this.isPlacer){
|
||||||
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
|
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
|
||||||
this.setInventorySlotContents(theSlot, WorldUtil.placeBlockAtSide(sideToManipulate, worldObj, this.pos, this.slots[theSlot]));
|
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(sideToManipulate, worldObj, this.pos, this.slots[theSlot]));
|
||||||
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
|
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
|
||||||
this.slots[theSlot] = null;
|
this.slots[theSlot] = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,11 +84,8 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
|
||||||
else if(this.isPlacer && PosUtil.getBlock(coordsBlock, worldObj).isReplaceable(worldObj, coordsBlock)){
|
else if(this.isPlacer && PosUtil.getBlock(coordsBlock, worldObj).isReplaceable(worldObj, coordsBlock)){
|
||||||
if(this.tank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME){
|
if(this.tank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME){
|
||||||
if(this.tank.getFluid().getFluid().getBlock() != null){
|
if(this.tank.getFluid().getFluid().getBlock() != null){
|
||||||
Block block = PosUtil.getBlock(coordsBlock, worldObj);
|
WorldUtil.useItemAtSide(sideToManipulate, worldObj, this.pos, new ItemStack(this.tank.getFluid().getFluid().getBlock()));
|
||||||
if(!(block instanceof IFluidBlock) && block != Blocks.lava && block != Blocks.water && block != Blocks.flowing_lava && block != Blocks.flowing_water){
|
this.tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
|
||||||
WorldUtil.placeBlockAtSide(sideToManipulate, worldObj, this.pos, new ItemStack(this.tank.getFluid().getFluid().getBlock()));
|
|
||||||
this.tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,12 +115,10 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(PosUtil.getBlock(boundPosition, worldObj).isReplaceable(worldObj, boundPosition)){
|
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
|
||||||
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
|
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(EnumFacing.UP, worldObj, boundPosition, this.slots[theSlot]));
|
||||||
this.setInventorySlotContents(theSlot, WorldUtil.placeBlockAtSide(EnumFacing.UP, worldObj, boundPosition, this.slots[theSlot]));
|
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
|
||||||
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
|
this.slots[theSlot] = null;
|
||||||
this.slots[theSlot] = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.util;
|
||||||
import cofh.api.energy.EnergyStorage;
|
import cofh.api.energy.EnergyStorage;
|
||||||
import cofh.api.energy.IEnergyReceiver;
|
import cofh.api.energy.IEnergyReceiver;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockLiquid;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -109,43 +110,45 @@ public class WorldUtil{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack placeBlockAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack){
|
public static ItemStack useItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack){
|
||||||
if(world instanceof WorldServer && stack != null && stack.getItem() != null){
|
if(world instanceof WorldServer && stack != null && stack.getItem() != null){
|
||||||
BlockPos offsetPos = pos.offset(side);
|
BlockPos offsetPos = pos.offset(side);
|
||||||
|
Block block = PosUtil.getBlock(offsetPos, world);
|
||||||
|
boolean replaceable = block.isReplaceable(world, offsetPos);
|
||||||
|
|
||||||
//Fluids
|
//Fluids
|
||||||
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
|
if(replaceable && FluidContainerRegistry.isFilledContainer(stack) && !(block instanceof IFluidBlock) && !(block instanceof BlockLiquid)){
|
||||||
if(fluid != null && fluid.getFluid().getBlock() != null && fluid.getFluid().getBlock().canPlaceBlockAt(world, offsetPos)){
|
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||||
Block block = PosUtil.getBlock(offsetPos, world);
|
if(fluid != null && fluid.getFluid().getBlock() != null && fluid.getFluid().getBlock().canPlaceBlockAt(world, offsetPos)){
|
||||||
if(!(block instanceof IFluidBlock) && block != Blocks.lava && block != Blocks.water && block != Blocks.flowing_lava && block != Blocks.flowing_water){
|
if(PosUtil.setBlock(offsetPos, world, fluid.getFluid().getBlock(), 0, 2)){
|
||||||
if(PosUtil.setBlock(pos, world, fluid.getFluid().getBlock(), 0, 2)){
|
|
||||||
return stack.getItem().getContainerItem(stack);
|
return stack.getItem().getContainerItem(stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Redstone
|
//Redstone
|
||||||
else if(stack.getItem() == Items.redstone){
|
else if(replaceable && stack.getItem() == Items.redstone){
|
||||||
PosUtil.setBlock(pos, world, Blocks.redstone_wire, 0, 2);
|
PosUtil.setBlock(offsetPos, world, Blocks.redstone_wire, 0, 2);
|
||||||
stack.stackSize--;
|
stack.stackSize--;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Plants
|
//Plants
|
||||||
else if(stack.getItem() instanceof IPlantable){
|
else if(replaceable && stack.getItem() instanceof IPlantable){
|
||||||
if(((IPlantable)stack.getItem()).getPlant(world, offsetPos).getBlock().canPlaceBlockAt(world, offsetPos)){
|
if(((IPlantable)stack.getItem()).getPlant(world, offsetPos).getBlock().canPlaceBlockAt(world, offsetPos)){
|
||||||
if(world.setBlockState(offsetPos, ((IPlantable)stack.getItem()).getPlant(world, offsetPos), 2)){
|
if(world.setBlockState(offsetPos, ((IPlantable)stack.getItem()).getPlant(world, offsetPos), 2)){
|
||||||
stack.stackSize--;
|
stack.stackSize--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Everything else
|
||||||
else{
|
else{
|
||||||
try{
|
try{
|
||||||
//Blocks
|
stack.onItemUse(FakePlayerUtil.getFakePlayer(world), world, offsetPos, side.getOpposite(), 0.5F, 0.5F, 0.5F);
|
||||||
stack.onItemUse(FakePlayerUtil.getFakePlayer(world), world, pos, side, 0, 0, 0);
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
catch(Exception e){
|
catch(Exception e){
|
||||||
ModUtil.LOGGER.error("Something that places Blocks at "+offsetPos.getX()+", "+offsetPos.getY()+", "+offsetPos.getZ()+" in World "+world.provider.getDimensionId()+" threw an Exception! Don't let that happen again!");
|
ModUtil.LOGGER.error("Something that places Blocks at "+offsetPos.getX()+", "+offsetPos.getY()+", "+offsetPos.getZ()+" in World "+world.provider.getDimensionId()+" threw an Exception! Don't let that happen again!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,6 +247,7 @@ public class WorldUtil{
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO make this work for the stupid new system
|
//TODO make this work for the stupid new system
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an ArrayList of ItemStacks to an Array of slots
|
* Add an ArrayList of ItemStacks to an Array of slots
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue