mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 20:22:33 +00:00
Change apothecary fluid to be stored in the blockstate
There are a couple benefits to this: - Light method no longer relies on forge method - Fluid changes detectable by observer - Tighter API (only take accepted fluids)
This commit is contained in:
1 parent
44a7d61956
commit
939b41e2c9
5 files changed
+80
-69
No files matched your search
@@ -10,20 +10,48 @@ package vazkii.botania.api.item;
|
||||
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Base Interface for the Petal Apothecary block. Can
|
||||
* be safely casted to TileEntity.
|
||||
*/
|
||||
public interface IPetalApothecary {
|
||||
enum State implements IStringSerializable {
|
||||
EMPTY,
|
||||
WATER,
|
||||
LAVA;
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String func_176610_l() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public Fluid asVanilla() {
|
||||
switch (this) {
|
||||
default:
|
||||
case EMPTY:
|
||||
return Fluids.EMPTY;
|
||||
case WATER:
|
||||
return Fluids.WATER;
|
||||
case LAVA:
|
||||
return Fluids.LAVA;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the contained fluid. Must be {@link Fluids#WATER}, {@link Fluids#LAVA}, or {@link Fluids#EMPTY}.
|
||||
* Set the contained fluid.
|
||||
*/
|
||||
public void setFluid(Fluid fluid);
|
||||
public void setFluid(State fluid);
|
||||
|
||||
/**
|
||||
* Get the contained fluid. Will be {@link Fluids#WATER}, {@link Fluids#LAVA}, or {@link Fluids#EMPTY}.
|
||||
* Get the contained fluid.
|
||||
*/
|
||||
public Fluid getFluid();
|
||||
public State getFluid();
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
|
||||
import vazkii.botania.api.item.IPetalApothecary;
|
||||
import vazkii.botania.client.core.handler.ClientTickHandler;
|
||||
import vazkii.botania.common.block.tile.TileAltar;
|
||||
|
||||
@@ -44,8 +45,8 @@ public class RenderTileAltar extends TileEntityRenderer<TileAltar> {
|
||||
ms.push();
|
||||
ms.translate(0.5, 1.5, 0.5);
|
||||
|
||||
boolean water = altar.getFluid() == Fluids.WATER;
|
||||
boolean lava = altar.getFluid() == Fluids.LAVA;
|
||||
boolean water = altar.getFluid() == IPetalApothecary.State.WATER;
|
||||
boolean lava = altar.getFluid() == IPetalApothecary.State.LAVA;
|
||||
if (water || lava) {
|
||||
ms.push();
|
||||
float s = 1F / 256F * 10F;
|
||||
|
||||
@@ -17,9 +17,12 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.EnumProperty;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.shapes.IBooleanFunction;
|
||||
@@ -34,6 +37,8 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
import vazkii.botania.api.internal.VanillaPacketDispatcher;
|
||||
import vazkii.botania.api.item.IPetalApothecary;
|
||||
import vazkii.botania.api.item.IPetalApothecary.State;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.tile.TileAltar;
|
||||
@@ -44,8 +49,11 @@ import vazkii.botania.common.item.rod.ItemWaterRod;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class BlockAltar extends BlockMod implements ITileEntityProvider {
|
||||
|
||||
public static final EnumProperty<State> FLUID = EnumProperty.create("fluid", State.class);
|
||||
private static final VoxelShape BASE = Block.makeCuboidShape(0, 0, 0, 16, 2, 16);
|
||||
private static final VoxelShape MIDDLE = Block.makeCuboidShape(2, 2, 2, 14, 12, 14);
|
||||
private static final VoxelShape TOP = Block.makeCuboidShape(2, 12, 2, 14, 20, 14);
|
||||
@@ -70,6 +78,13 @@ public class BlockAltar extends BlockMod implements ITileEntityProvider {
|
||||
protected BlockAltar(Variant v, Block.Properties builder) {
|
||||
super(builder);
|
||||
this.variant = v;
|
||||
setDefaultState(getDefaultState().with(FLUID, State.EMPTY));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
||||
super.fillStateContainer(builder);
|
||||
builder.add(FLUID);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -88,64 +103,53 @@ public class BlockAltar extends BlockMod implements ITileEntityProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightValue(@Nonnull BlockState state, IBlockReader world, @Nonnull BlockPos pos) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te instanceof TileAltar && ((TileAltar) te).getFluid() == Fluids.LAVA) {
|
||||
return 15;
|
||||
} else {
|
||||
return super.getLightValue(state, world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
|
||||
TileAltar tile = (TileAltar) world.getTileEntity(pos);
|
||||
State fluid = tile.getFluid();
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
if (player.isSneaking()) {
|
||||
InventoryHelper.withdrawFromInventory(tile, player);
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(tile);
|
||||
return ActionResultType.SUCCESS;
|
||||
} else if (tile.isEmpty() && tile.getFluid() == Fluids.WATER && stack.isEmpty()) {
|
||||
} else if (tile.isEmpty() && fluid == State.WATER && stack.isEmpty()) {
|
||||
tile.trySetLastRecipe(player);
|
||||
return ActionResultType.SUCCESS;
|
||||
} else {
|
||||
if (!stack.isEmpty() && tile.getFluid() != Fluids.EMPTY && isValidFluidContainerToFill(stack, tile.getFluid()) && !Botania.gardenOfGlassLoaded) {
|
||||
if (!stack.isEmpty() && fluid != State.EMPTY && isValidFluidContainerToFill(stack, tile.getFluid().asVanilla()) && !Botania.gardenOfGlassLoaded) {
|
||||
if (!player.abilities.isCreativeMode) {
|
||||
//support bucket stacks
|
||||
if (stack.getCount() == 1) {
|
||||
player.setHeldItem(hand, fill(tile.getFluid(), stack));
|
||||
player.setHeldItem(hand, fill(tile.getFluid().asVanilla(), stack));
|
||||
} else {
|
||||
player.inventory.placeItemBackInInventory(player.world, new ItemStack(stack.getItem()));
|
||||
stack.shrink(1);
|
||||
}
|
||||
}
|
||||
|
||||
tile.setFluid(Fluids.EMPTY);
|
||||
tile.setFluid(State.EMPTY);
|
||||
world.getChunkProvider().getLightManager().checkBlock(pos);
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
} else if (!stack.isEmpty() && (isValidFluidContainerToDrain(stack, Fluids.WATER) || stack.getItem() == ModItems.waterRod && ManaItemHandler.instance().requestManaExact(stack, player, ItemWaterRod.COST, false))) {
|
||||
if (tile.getFluid() == Fluids.EMPTY) {
|
||||
if (tile.getFluid() == State.EMPTY) {
|
||||
if (stack.getItem() == ModItems.waterRod) {
|
||||
ManaItemHandler.instance().requestManaExact(stack, player, ItemWaterRod.COST, true);
|
||||
} else if (!player.abilities.isCreativeMode) {
|
||||
player.setHeldItem(hand, drain(Fluids.WATER, stack));
|
||||
}
|
||||
|
||||
tile.setFluid(Fluids.WATER);
|
||||
world.getChunkProvider().getLightManager().checkBlock(pos);
|
||||
tile.setFluid(State.WATER);
|
||||
}
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
} else if (!stack.isEmpty() && isValidFluidContainerToDrain(stack, Fluids.LAVA)) {
|
||||
if (tile.getFluid() == Fluids.EMPTY) {
|
||||
if (tile.getFluid() == State.EMPTY) {
|
||||
if (!player.abilities.isCreativeMode) {
|
||||
player.setHeldItem(hand, drain(Fluids.LAVA, stack));
|
||||
}
|
||||
|
||||
tile.setFluid(Fluids.LAVA);
|
||||
world.getChunkProvider().getLightManager().checkBlock(pos);
|
||||
tile.setFluid(State.LAVA);
|
||||
}
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
@@ -158,12 +162,9 @@ public class BlockAltar extends BlockMod implements ITileEntityProvider {
|
||||
@Override
|
||||
public void fillWithRain(World world, BlockPos pos) {
|
||||
if (world.rand.nextInt(20) == 1) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileAltar) {
|
||||
TileAltar altar = (TileAltar) tile;
|
||||
if (altar.getFluid() == Fluids.EMPTY) {
|
||||
altar.setFluid(Fluids.WATER);
|
||||
}
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if (state.get(FLUID) == State.EMPTY) {
|
||||
world.setBlockState(pos, state.with(FLUID, State.WATER));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +236,6 @@ public class BlockAltar extends BlockMod implements ITileEntityProvider {
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(BlockState state, World world, BlockPos pos) {
|
||||
TileAltar altar = (TileAltar) world.getTileEntity(pos);
|
||||
return altar.getFluid() == Fluids.WATER ? 15 : 0;
|
||||
return state.get(FLUID) == State.WATER ? 15 : 0;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
import vazkii.botania.api.item.IPetalApothecary;
|
||||
import vazkii.botania.api.state.BotaniaStateProps;
|
||||
import vazkii.botania.api.state.enums.AlfPortalState;
|
||||
import vazkii.botania.api.state.enums.LuminizerVariant;
|
||||
@@ -66,7 +67,8 @@ public final class ModBlocks {
|
||||
public static final Block redFlower = new BlockModFlower(DyeColor.RED, Block.Properties.from(whiteFlower));
|
||||
public static final Block blackFlower = new BlockModFlower(DyeColor.BLACK, Block.Properties.from(whiteFlower));
|
||||
|
||||
public static final Block defaultAltar = new BlockAltar(BlockAltar.Variant.DEFAULT, Block.Properties.create(Material.ROCK).hardnessAndResistance(3.5F).sound(SoundType.STONE));
|
||||
public static final Block defaultAltar = new BlockAltar(BlockAltar.Variant.DEFAULT, Block.Properties.create(Material.ROCK).hardnessAndResistance(3.5F).sound(SoundType.STONE)
|
||||
.func_235838_a_(s -> s.get(BlockAltar.FLUID) == IPetalApothecary.State.LAVA ? 15 : 0));
|
||||
public static final Block forestAltar = new BlockAltar(BlockAltar.Variant.FOREST, Block.Properties.from(defaultAltar));
|
||||
public static final Block plainsAltar = new BlockAltar(BlockAltar.Variant.PLAINS, Block.Properties.from(defaultAltar));
|
||||
public static final Block mountainAltar = new BlockAltar(BlockAltar.Variant.MOUNTAIN, Block.Properties.from(defaultAltar));
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
@@ -49,6 +50,7 @@ import vazkii.botania.api.recipe.IPetalRecipe;
|
||||
import vazkii.botania.client.core.handler.HUDHandler;
|
||||
import vazkii.botania.client.core.helper.RenderHelper;
|
||||
import vazkii.botania.client.fx.SparkleParticleData;
|
||||
import vazkii.botania.common.block.BlockAltar;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.core.handler.ModSounds;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
@@ -66,12 +68,8 @@ 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_FLUID = "fluid";
|
||||
|
||||
private static final String ITEM_TAG_APOTHECARY_SPAWNED = "ApothecarySpawned";
|
||||
|
||||
private Fluid fluid = Fluids.EMPTY;
|
||||
|
||||
private List<ItemStack> lastRecipe = null;
|
||||
private int recipeKeepTicks = 0;
|
||||
|
||||
@@ -102,10 +100,10 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
|
||||
boolean hasFluidCapability = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).isPresent();
|
||||
|
||||
if (getFluid() == Fluids.EMPTY) {
|
||||
if (getFluid() == State.EMPTY) {
|
||||
// XXX: special handling for now since fish buckets don't have fluid cap, may need to be changed later
|
||||
if (stack.getItem() instanceof FishBucketItem && ((FishBucketItem) stack.getItem()).getFluid() == Fluids.WATER) {
|
||||
setFluid(Fluids.WATER);
|
||||
setFluid(State.WATER);
|
||||
((FishBucketItem) stack.getItem()).onLiquidPlaced(world, stack, getPos().up()); // Spawns the fish
|
||||
item.setItem(new ItemStack(Items.BUCKET));
|
||||
return true;
|
||||
@@ -118,12 +116,12 @@ 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) {
|
||||
setFluid(Fluids.WATER);
|
||||
setFluid(State.WATER);
|
||||
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) {
|
||||
setFluid(Fluids.LAVA);
|
||||
setFluid(State.LAVA);
|
||||
fluidHandler.drain(new FluidStack(Fluids.LAVA, FluidAttributes.BUCKET_VOLUME), IFluidHandler.FluidAction.EXECUTE);
|
||||
item.setItem(fluidHandler.getContainer());
|
||||
return true;
|
||||
@@ -133,7 +131,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getFluid() == Fluids.LAVA) {
|
||||
if (getFluid() == State.LAVA) {
|
||||
item.setFire(100);
|
||||
return true;
|
||||
}
|
||||
@@ -154,7 +152,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
outputItem.addTag(ITEM_TAG_APOTHECARY_SPAWNED);
|
||||
world.addEntity(outputItem);
|
||||
|
||||
setFluid(Fluids.EMPTY);
|
||||
setFluid(State.EMPTY);
|
||||
|
||||
world.addBlockEvent(getPos(), getBlockState().getBlock(), CRAFT_EFFECT_EVENT, 0);
|
||||
});
|
||||
@@ -280,7 +278,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
}
|
||||
}
|
||||
|
||||
if (getFluid() == Fluids.LAVA) {
|
||||
if (getFluid() == State.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);
|
||||
@@ -295,21 +293,6 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacketNBT(CompoundNBT cmp) {
|
||||
super.writePacketNBT(cmp);
|
||||
|
||||
cmp.putString(TAG_FLUID, Registry.FLUID.getKey(fluid).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readPacketNBT(CompoundNBT cmp) {
|
||||
super.readPacketNBT(cmp);
|
||||
|
||||
ResourceLocation id = new ResourceLocation(cmp.getString(TAG_FLUID));
|
||||
fluid = Registry.FLUID.getOrDefault(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean receiveClientEvent(int id, int param) {
|
||||
switch (id) {
|
||||
@@ -345,16 +328,13 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFluid(Fluid fluid) {
|
||||
Preconditions.checkArgument(fluid == Fluids.WATER || fluid == Fluids.LAVA || fluid == Fluids.EMPTY);
|
||||
this.fluid = fluid;
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
|
||||
world.updateComparatorOutputLevel(getPos(), getBlockState().getBlock());
|
||||
public void setFluid(State fluid) {
|
||||
world.setBlockState(getPos(), getBlockState().with(BlockAltar.FLUID, fluid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fluid getFluid() {
|
||||
return fluid;
|
||||
public State getFluid() {
|
||||
return getBlockState().get(BlockAltar.FLUID);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@@ -397,7 +377,7 @@ public class TileAltar extends TileSimpleInventory implements IPetalApothecary,
|
||||
|
||||
angle += anglePer;
|
||||
}
|
||||
} else if (recipeKeepTicks > 0 && getFluid() == Fluids.WATER) {
|
||||
} else if (recipeKeepTicks > 0 && getFluid() == State.WATER) {
|
||||
String s = I18n.format("botaniamisc.altarRefill0");
|
||||
mc.fontRenderer.func_238421_b_(ms, s, xc - mc.fontRenderer.getStringWidth(s) / 2, yc + 10, 0xFFFFFF);
|
||||
s = I18n.format("botaniamisc.altarRefill1");
|
||||
|
||||
Reference in new issue
Block a user