Skip to content

Commit

Permalink
Fixed black hole tanks not writing nbt fluid when placed, closes #451
Browse files Browse the repository at this point in the history
  • Loading branch information
Buuz135 committed Nov 11, 2018
1 parent d387410 commit f15ac5d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.buuz135.industrial.utils.RecipeUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
Expand All @@ -49,6 +50,7 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.ndrei.teslacorelib.items.MachineCaseItem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand All @@ -70,6 +72,11 @@ public void createRecipe() {

@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {

}

@Override
public void breakBlock(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState state) {
if (world.getTileEntity(pos) instanceof BlackHoleTankTile) {
BlackHoleTankTile tile = (BlackHoleTankTile) world.getTileEntity(pos);
ItemStack stack = new ItemStack(Item.getItemFromBlock(this), 1);
Expand All @@ -79,16 +86,27 @@ public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos
stack.setTagCompound(tile.getTank().getFluid().writeToNBT(new NBTTagCompound()));
}
}
drops.add(stack);
float f = 0.7F;
float d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
float d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
float d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
EntityItem entityitem = new EntityItem(world, pos.getX() + d0, pos.getY() + d1, pos.getZ() + d2, stack);
entityitem.setDefaultPickupDelay();
if (stack.hasTagCompound()) {
entityitem.getItem().setTagCompound(stack.getTagCompound().copy());
}
world.spawnEntity(entityitem);
}
super.breakBlock(world, pos, state);
}

@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
super.onBlockPlacedBy(world, pos, state, placer, stack);
if (stack.hasTagCompound() && world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof BlackHoleTankTile && FluidRegistry.isFluidRegistered(stack.getTagCompound().getString("FluidName"))) {
BlackHoleTankTile tile = (BlackHoleTankTile) world.getTileEntity(pos);
tile.getTank().fill(new FluidStack(FluidRegistry.getFluid(stack.getTagCompound().getString("FluidName")), stack.getTagCompound().getInteger("Amount")), true);
System.out.println(stack.getTagCompound());
tile.getTank().fill(new FluidStack(FluidRegistry.getFluid(stack.getTagCompound().getString("FluidName")), stack.getTagCompound().getInteger("Amount"), stack.getTagCompound().getCompoundTag("Tag")), true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -49,11 +50,6 @@ public BlackHoleUnitBlock() {

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
world.removeTileEntity(pos);
}

@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
if (world.getTileEntity(pos) instanceof BlackHoleUnitTile) {
BlackHoleUnitTile tile = (BlackHoleUnitTile) world.getTileEntity(pos);
ItemStack stack = new ItemStack(Item.getItemFromBlock(this), 1);
Expand All @@ -65,8 +61,23 @@ public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos
if (tile.getItemStack().hasTagCompound())
stack.getTagCompound().setTag(BlackHoleUnitTile.NBT_ITEM_NBT, tile.getItemStack().getTagCompound());
}
drops.add(stack);
float f = 0.7F;
float d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
float d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
float d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
EntityItem entityitem = new EntityItem(world, pos.getX() + d0, pos.getY() + d1, pos.getZ() + d2, stack);
entityitem.setDefaultPickupDelay();
if (stack.hasTagCompound()) {
entityitem.getItem().setTagCompound(stack.getTagCompound().copy());
}
world.spawnEntity(entityitem);
}
world.removeTileEntity(pos);
}

@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {

}

@Override
Expand Down

0 comments on commit f15ac5d

Please sign in to comment.