mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 19:29:31 +00:00
Clean up how the apothecary stores its fluids, probably eliminates some consistency bugs when the water/lava flags were out of sync
This commit is contained in:
1 parent
7ffdc27c49
commit
435e5e4ff0
4 files changed
+41
-49
No files matched your search
@@ -10,6 +10,9 @@
|
||||
*/
|
||||
package vazkii.botania.api.item;
|
||||
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
|
||||
/**
|
||||
* Base Interface for the Petal Apothecary block. Can
|
||||
* be safely casted to TileEntity.
|
||||
@@ -17,13 +20,12 @@ package vazkii.botania.api.item;
|
||||
public interface IPetalApothecary {
|
||||
|
||||
/**
|
||||
* Sets if the the apothecary has water or not.
|
||||
* Set the contained fluid. Must be {@link Fluids#WATER}, {@link Fluids#LAVA}, or {@link Fluids#EMPTY}.
|
||||
*/
|
||||
public void setWater(boolean water);
|
||||
public void setFluid(Fluid fluid);
|
||||
|
||||
/**
|
||||
* Does the apothecary have water in it?
|
||||
* Get the contained fluid. Will be {@link Fluids#WATER}, {@link Fluids#LAVA}, or {@link Fluids#EMPTY}.
|
||||
*/
|
||||
public boolean hasWater();
|
||||
|
||||
public Fluid getFluid();
|
||||
}
|
||||
@@ -41,8 +41,8 @@ public class RenderTileAltar extends TileEntityRenderer<TileAltar> {
|
||||
GlStateManager.translated(d0 + 0.5, d1 + 1.5, d2 + 0.5);
|
||||
GlStateManager.enableRescaleNormal();
|
||||
|
||||
boolean water = altar.hasWater();
|
||||
boolean lava = altar.hasLava();
|
||||
boolean water = altar.getFluid() == Fluids.WATER;
|
||||
boolean lava = altar.getFluid() == Fluids.LAVA;
|
||||
if(water || lava) {
|
||||
GlStateManager.pushMatrix();
|
||||
float s = 1F / 256F * 10F;
|
||||
|
||||
@@ -110,7 +110,7 @@ public class BlockAltar extends BlockMod implements ILexiconable {
|
||||
if(world.getBlockState(pos).getBlock() != this)
|
||||
return world.getBlockState(pos).getLightValue(world, pos);
|
||||
TileAltar tile = (TileAltar) world.getTileEntity(pos);
|
||||
return tile != null && tile.hasLava ? 15 : 0;
|
||||
return tile != null && tile.getFluid() == Fluids.LAVA ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,19 +121,19 @@ public class BlockAltar extends BlockMod implements ILexiconable {
|
||||
InventoryHelper.withdrawFromInventory(tile, player);
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(tile);
|
||||
return true;
|
||||
} else if(tile.isEmpty() && tile.hasWater && stack.isEmpty()) {
|
||||
} else if(tile.isEmpty() && tile.getFluid() == Fluids.WATER && stack.isEmpty()) {
|
||||
tile.trySetLastRecipe(player);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if(!stack.isEmpty() && (isValidWaterContainer(stack) || stack.getItem() == ModItems.waterRod && ManaItemHandler.requestManaExact(stack, player, ItemWaterRod.COST, false))) {
|
||||
if(!tile.hasWater) {
|
||||
if(tile.getFluid() == Fluids.EMPTY) {
|
||||
if(stack.getItem() == ModItems.waterRod)
|
||||
ManaItemHandler.requestManaExact(stack, player, ItemWaterRod.COST, true);
|
||||
else if(!player.abilities.isCreativeMode)
|
||||
player.setHeldItem(hand, drain(Fluids.WATER, stack));
|
||||
|
||||
tile.setWater(true);
|
||||
tile.setFluid(Fluids.WATER);
|
||||
world.updateComparatorOutputLevel(pos, this);
|
||||
world.getChunkProvider().getLightManager().checkBlock(pos);
|
||||
}
|
||||
@@ -143,14 +143,13 @@ public class BlockAltar extends BlockMod implements ILexiconable {
|
||||
if(!player.abilities.isCreativeMode)
|
||||
player.setHeldItem(hand, drain(Fluids.LAVA, stack));
|
||||
|
||||
tile.setLava(true);
|
||||
tile.setWater(false);
|
||||
tile.setFluid(Fluids.LAVA);
|
||||
world.updateComparatorOutputLevel(pos, this);
|
||||
world.getChunkProvider().getLightManager().checkBlock(pos);
|
||||
|
||||
return true;
|
||||
} else if(!stack.isEmpty() && stack.getItem() == Items.BUCKET && (tile.hasWater || tile.hasLava) && !Botania.gardenOfGlassLoaded) {
|
||||
ItemStack bucket = tile.hasLava ? new ItemStack(Items.LAVA_BUCKET) : new ItemStack(Items.WATER_BUCKET);
|
||||
} else if(!stack.isEmpty() && stack.getItem() == Items.BUCKET && tile.getFluid() != Fluids.EMPTY && !Botania.gardenOfGlassLoaded) {
|
||||
ItemStack bucket = new ItemStack(tile.getFluid().getFilledBucket());
|
||||
if(stack.getCount() == 1)
|
||||
player.setHeldItem(hand, bucket);
|
||||
else {
|
||||
@@ -158,9 +157,7 @@ public class BlockAltar extends BlockMod implements ILexiconable {
|
||||
stack.shrink(1);
|
||||
}
|
||||
|
||||
if(tile.hasLava)
|
||||
tile.setLava(false);
|
||||
else tile.setWater(false);
|
||||
tile.setFluid(Fluids.EMPTY);
|
||||
world.updateComparatorOutputLevel(pos, this);
|
||||
world.getChunkProvider().getLightManager().checkBlock(pos);
|
||||
|
||||
@@ -177,8 +174,8 @@ public class BlockAltar extends BlockMod implements ILexiconable {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileAltar) {
|
||||
TileAltar altar = (TileAltar) tile;
|
||||
if(!altar.hasLava && !altar.hasWater)
|
||||
altar.setWater(true);
|
||||
if(altar.getFluid() == Fluids.EMPTY)
|
||||
altar.setFluid(Fluids.WATER);
|
||||
world.updateComparatorOutputLevel(pos, this);
|
||||
}
|
||||
}
|
||||
@@ -231,7 +228,7 @@ public class BlockAltar extends BlockMod implements ILexiconable {
|
||||
@Override
|
||||
public int getComparatorInputOverride(BlockState state, World world, BlockPos pos) {
|
||||
TileAltar altar = (TileAltar) world.getTileEntity(pos);
|
||||
return altar.hasWater ? 15 : 0;
|
||||
return altar.getFluid() == Fluids.WATER ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
@@ -17,11 +18,13 @@ import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -38,6 +41,7 @@ import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.internal.VanillaPacketDispatcher;
|
||||
@@ -66,13 +70,11 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
private static final int SET_KEEP_TICKS_EVENT = 0;
|
||||
private static final int CRAFT_EFFECT_EVENT = 1;
|
||||
|
||||
private static final String TAG_HAS_WATER = "hasWater";
|
||||
private static final String TAG_HAS_LAVA = "hasLava";
|
||||
private static final String TAG_FLUID = "fluid";
|
||||
|
||||
private static final String ITEM_TAG_APOTHECARY_SPAWNED = "ApothecarySpawned";
|
||||
|
||||
public boolean hasWater = false;
|
||||
public boolean hasLava = false;
|
||||
private Fluid fluid = Fluids.EMPTY;
|
||||
|
||||
private List<ItemStack> lastRecipe = null;
|
||||
private int recipeKeepTicks = 0;
|
||||
@@ -108,7 +110,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
|
||||
boolean hasFluidCapability = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).isPresent();
|
||||
|
||||
if(!hasWater() && !hasLava()) {
|
||||
if(getFluid() == Fluids.EMPTY) {
|
||||
if(hasFluidCapability) {
|
||||
IFluidHandlerItem fluidHandler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).orElseThrow(NullPointerException::new);
|
||||
|
||||
@@ -116,13 +118,13 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
FluidStack drainLava = fluidHandler.drain(new FluidStack(Fluids.LAVA, FluidAttributes.BUCKET_VOLUME), IFluidHandler.FluidAction.SIMULATE);
|
||||
|
||||
if(!drainWater.isEmpty() && drainWater.getFluid() == Fluids.WATER && drainWater.getAmount() == FluidAttributes.BUCKET_VOLUME) {
|
||||
setWater(true);
|
||||
setFluid(Fluids.WATER);
|
||||
world.updateComparatorOutputLevel(pos, world.getBlockState(pos).getBlock());
|
||||
fluidHandler.drain(new FluidStack(Fluids.WATER, FluidAttributes.BUCKET_VOLUME), IFluidHandler.FluidAction.EXECUTE);
|
||||
item.setItem(fluidHandler.getContainer());
|
||||
return true;
|
||||
} else if(!drainLava.isEmpty() && drainLava.getFluid() == Fluids.LAVA && drainLava.getAmount() == FluidAttributes.BUCKET_VOLUME) {
|
||||
setLava(true);
|
||||
setFluid(Fluids.LAVA);
|
||||
world.updateComparatorOutputLevel(pos, world.getBlockState(pos).getBlock());
|
||||
fluidHandler.drain(new FluidStack(Fluids.LAVA, FluidAttributes.BUCKET_VOLUME), IFluidHandler.FluidAction.EXECUTE);
|
||||
item.setItem(fluidHandler.getContainer());
|
||||
@@ -133,7 +135,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
return false;
|
||||
}
|
||||
|
||||
if(hasLava()) {
|
||||
if(getFluid() == Fluids.LAVA) {
|
||||
item.setFire(100);
|
||||
return true;
|
||||
}
|
||||
@@ -153,7 +155,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
outputItem.addTag(ITEM_TAG_APOTHECARY_SPAWNED);
|
||||
world.addEntity(outputItem);
|
||||
|
||||
setWater(false);
|
||||
setFluid(Fluids.EMPTY);
|
||||
world.updateComparatorOutputLevel(pos, world.getBlockState(pos).getBlock());
|
||||
|
||||
world.addBlockEvent(getPos(), getBlockState().getBlock(), CRAFT_EFFECT_EVENT, 0);
|
||||
@@ -271,7 +273,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
}
|
||||
}
|
||||
|
||||
if(hasLava()) {
|
||||
if(getFluid() == Fluids.LAVA) {
|
||||
world.addParticle(ParticleTypes.SMOKE, pos.getX() + 0.5 + Math.random() * 0.4 - 0.2, pos.getY() + 1, pos.getZ() + 0.5 + Math.random() * 0.4 - 0.2, 0, 0.05, 0);
|
||||
if(Math.random() > 0.9)
|
||||
world.addParticle(ParticleTypes.LAVA, pos.getX() + 0.5 + Math.random() * 0.4 - 0.2, pos.getY() + 1, pos.getZ() + 0.5 + Math.random() * 0.4 - 0.2, 0, 0.01, 0);
|
||||
@@ -287,16 +289,15 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
public void writePacketNBT(CompoundNBT cmp) {
|
||||
super.writePacketNBT(cmp);
|
||||
|
||||
cmp.putBoolean(TAG_HAS_WATER, hasWater());
|
||||
cmp.putBoolean(TAG_HAS_LAVA, hasLava());
|
||||
cmp.putString(TAG_FLUID, fluid.getRegistryName().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readPacketNBT(CompoundNBT cmp) {
|
||||
super.readPacketNBT(cmp);
|
||||
|
||||
hasWater = cmp.getBoolean(TAG_HAS_WATER);
|
||||
hasLava = cmp.getBoolean(TAG_HAS_LAVA);
|
||||
ResourceLocation id = new ResourceLocation(cmp.getString(TAG_FLUID));
|
||||
fluid = ForgeRegistries.FLUIDS.getValue(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -336,23 +337,15 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWater(boolean water) {
|
||||
hasWater = water;
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos);
|
||||
}
|
||||
|
||||
public void setLava(boolean lava) {
|
||||
hasLava = lava;
|
||||
public void setFluid(Fluid fluid) {
|
||||
Preconditions.checkArgument(fluid == Fluids.WATER || fluid == Fluids.LAVA || fluid == Fluids.EMPTY);
|
||||
this.fluid = fluid;
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasWater() {
|
||||
return hasWater;
|
||||
}
|
||||
|
||||
public boolean hasLava() {
|
||||
return hasLava;
|
||||
public Fluid getFluid() {
|
||||
return fluid;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@@ -398,7 +391,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
angle += anglePer;
|
||||
}
|
||||
net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
|
||||
} else if(recipeKeepTicks > 0 && hasWater) {
|
||||
} else if(recipeKeepTicks > 0 && getFluid() == Fluids.WATER) {
|
||||
String s = I18n.format("botaniamisc.altarRefill0");
|
||||
mc.fontRenderer.drawStringWithShadow(s, xc - mc.fontRenderer.getStringWidth(s) / 2, yc + 10, 0xFFFFFF);
|
||||
s = I18n.format("botaniamisc.altarRefill1");
|
||||
|
||||
Reference in new issue
Block a user