Skip to content

Commit

Permalink
Cauldron fluid now applies effects for all fluids inside instead of j…
Browse files Browse the repository at this point in the history
…ust water

Following effects exist:
* Water extinguishes entities as before
* Boiling liquids boil entities alive
* Hot liquids deal lava damage
* Potions apply to the player
  • Loading branch information
KnightMiner committed Jun 30, 2018
1 parent 7be5fd9 commit d322fda
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 16 deletions.
Expand Up @@ -77,7 +77,7 @@ public void fillWithRain(World world, BlockPos pos) {
if((Config.fasterCauldronRain || world.rand.nextInt(20) == 0)
&& world.getBiomeProvider().getTemperatureAtHeight(world.getBiome(pos).getTemperature(pos), pos.getY()) >= 0.15F) {
IBlockState state = world.getBlockState(pos);
int level = state.getValue(levelsProp());
int level = getLevel(state);
if(level < (Config.enableBiggerCauldron ? 4 : 3)) {
setWaterLevel(world, pos, state, level+1);
}
Expand All @@ -91,15 +91,24 @@ public void fillWithRain(World world, BlockPos pos) {
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
TileEntity te = world.getTileEntity(pos);
// do not estinguish unless the current contents are water
if(te instanceof TileCauldron && !((TileCauldron) te).isWater()) {
if(!(te instanceof TileCauldron)) {
return;
}
if(world.isRemote) {
return;
}

int i = state.getValue(levelsProp());
float f = pos.getY() + ((Config.enableBiggerCauldron ? 3.0F : 6.0F) + 3 * i) / 16.0F;
if (!world.isRemote && entity.isBurning() && i > 0 && entity.getEntityBoundingBox().minY <= f) {
entity.extinguish();
this.setWaterLevel(world, pos, state, i - 1);
// ensure the entity is touching the fluid inside
int level = getLevel(state);
float f = pos.getY() + ((Config.enableBiggerCauldron ? 2.5F : 5.5F) + 3 * level) / 16.0F;
if (level > 0 && entity.getEntityBoundingBox().minY <= f) {
// if so, have the TE handle it
int newLevel = ((TileCauldron)te).onEntityCollide(entity, level);
// if the level changed, update it
if(level != newLevel) {
this.setWaterLevel(world, pos, state, newLevel);
}

}
}

Expand Down Expand Up @@ -132,7 +141,7 @@ public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Rand
return;
}

int level = state.getValue(levelsProp());
int level = getLevel(state);
if(level == 0) {
return;
}
Expand Down Expand Up @@ -165,10 +174,6 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En
}

/* 4 bottle support */
public static PropertyInteger levelsProp() {
return Config.enableBiggerCauldron ? LEVELS : LEVEL;
}

@Override
public void setWaterLevel(World worldIn, BlockPos pos, IBlockState state, int level) {
// if 4, set 4 prop
Expand All @@ -179,9 +184,16 @@ public void setWaterLevel(World worldIn, BlockPos pos, IBlockState state, int le
worldIn.updateComparatorOutputLevel(pos, this);
}

public int getLevel(IBlockState state) {
if(Config.enableBiggerCauldron) {
return state.getValue(LEVELS);
}
return state.getValue(LEVEL);
}

@Override
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) {
return blockState.getValue(levelsProp());
public int getComparatorInputOverride(IBlockState state, World worldIn, BlockPos pos) {
return getLevel(state);
}

/**
Expand All @@ -202,7 +214,7 @@ public IBlockState getStateFromMeta(int meta) {
*/
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(levelsProp());
return getLevel(state);
}

public static enum CauldronContents implements IStringSerializable {
Expand Down
@@ -1,9 +1,11 @@
package knightminer.inspirations.recipes.tileentity;

import java.util.List;
import javax.annotation.Nonnull;

import knightminer.inspirations.common.Config;
import knightminer.inspirations.library.InspirationsRegistry;
import knightminer.inspirations.library.Util;
import knightminer.inspirations.library.recipe.cauldron.ICauldronRecipe;
import knightminer.inspirations.library.recipe.cauldron.ICauldronRecipe.CauldronState;
import knightminer.inspirations.recipes.InspirationsRecipes;
Expand All @@ -12,15 +14,20 @@
import net.minecraft.block.BlockFire;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionUtils;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
Expand All @@ -31,6 +38,8 @@
import net.minecraftforge.items.ItemHandlerHelper;

public class TileCauldron extends TileEntity {
public static final DamageSource DAMAGE_BOIL = new DamageSource(Util.prefix("boiling")).setDamageBypassesArmor();

private CauldronState state;

public TileCauldron() {
Expand Down Expand Up @@ -109,7 +118,7 @@ public static boolean interact(World world, BlockPos pos, IBlockState blockState

// other properties
boolean boiling = world.getBlockState(pos.down()).getBlock() instanceof BlockFire;
int level = blockState.getValue(BlockEnhancedCauldron.levelsProp());
int level = InspirationsRecipes.cauldron.getLevel(blockState);

// grab recipe
ICauldronRecipe recipe = InspirationsRegistry.getCauldronResult(stack, boiling, level, state);
Expand Down Expand Up @@ -170,6 +179,54 @@ public static boolean interact(World world, BlockPos pos, IBlockState blockState
return true;
}

public int onEntityCollide(Entity entity, int level) {
// whether a level should be consumed
switch(this.getContentType()) {
case FLUID:
// estinguish fire
if(this.isWater()) {
if(entity.isBurning()) {
entity.extinguish();
level = level - 1;
}
} else {
// set fire if the liquid is hot
Fluid fluid = state.getFluid();
if(fluid.getTemperature() > 450 && !entity.isImmuneToFire()) {
entity.attackEntityFrom(DamageSource.LAVA, 4.0F);
entity.setFire(15);
break;
}
}
// continue for boiling
case DYE:
// if the cauldron is boiling, boiling the entity
if (world.getBlockState(pos.down()).getBlock() == Blocks.FIRE) {
entity.attackEntityFrom(DAMAGE_BOIL, 2.0F);
}
break;
case POTION:
// apply potion effects
if(entity instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) entity;
List<PotionEffect> effects = state.getPotion().getEffects();
// if any of the effects are not currently on the player, apply it and lower the level
if(effects.stream().anyMatch(effect -> !living.isPotionActive(effect.getPotion()))) {
for(PotionEffect effect : effects) {
if (effect.getPotion().isInstant()) {
effect.getPotion().affectEntity(living, living, living, effect.getAmplifier(), 1.0D);
} else {
living.addPotionEffect(new PotionEffect(effect));
}
}
level = level - 1;
}
}
break;
}
return level;
}

public IBlockState writeExtendedBlockState(IExtendedBlockState state) {
// just pull the texture right from the fluid
if(this.state != CauldronState.WATER && getContentType() == CauldronContents.FLUID) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/inspirations/lang/en_us.lang
Expand Up @@ -139,6 +139,8 @@ fluid.inspirations.beetroot_soup=Beetroot Soup
fluid.inspirations.rabbit_stew=Rabbit Stew
fluid.inspirations.milk=Milk

death.attack.inspirations.boiling=%s was boiled alive

# JEI
gui.jei.anvil_smashing.title=Anvil Smashing
gui.jei.cauldron.title=Cauldron
Expand Down

0 comments on commit d322fda

Please sign in to comment.