Remote extinguishing

- Make splash water bottles extinguish lit blaze burners
This commit is contained in:
PepperBell 2021-07-08 23:21:51 -07:00
parent cf3ef8c229
commit bdbd5c9533

View file

@ -1,11 +1,24 @@
package com.simibubi.create.content.contraptions.processing.burner; package com.simibubi.create.content.contraptions.processing.burner;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllSoundEvents; import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerTileEntity.FuelType; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerTileEntity.FuelType;
import net.minecraft.block.BlockState;
import net.minecraft.block.CampfireBlock;
import net.minecraft.entity.projectile.EggEntity; import net.minecraft.entity.projectile.EggEntity;
import net.minecraft.entity.projectile.PotionEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionUtils;
import net.minecraft.potion.Potions;
import net.minecraft.tags.BlockTags;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
@ -18,6 +31,11 @@ import net.minecraftforge.fml.common.Mod;
public class BlazeBurnerHandler { public class BlazeBurnerHandler {
@SubscribeEvent @SubscribeEvent
public static void onThrowableImpact(ProjectileImpactEvent.Throwable event) {
thrownEggsGetEatenByBurner(event);
splashExtinguishesBurner(event);
}
public static void thrownEggsGetEatenByBurner(ProjectileImpactEvent.Throwable event) { public static void thrownEggsGetEatenByBurner(ProjectileImpactEvent.Throwable event) {
if (!(event.getThrowable() instanceof EggEntity)) if (!(event.getThrowable() instanceof EggEntity))
return; return;
@ -54,4 +72,41 @@ public class BlazeBurnerHandler {
AllSoundEvents.BLAZE_MUNCH.playOnServer(world, heater.getPos()); AllSoundEvents.BLAZE_MUNCH.playOnServer(world, heater.getPos());
} }
public static void splashExtinguishesBurner(ProjectileImpactEvent.Throwable event) {
if (event.getThrowable().world.isRemote)
return;
if (!(event.getThrowable() instanceof PotionEntity))
return;
PotionEntity entity = (PotionEntity) event.getThrowable();
if (event.getRayTraceResult()
.getType() != RayTraceResult.Type.BLOCK)
return;
ItemStack stack = entity.getItem();
Potion potion = PotionUtils.getPotionFromItem(stack);
if (potion == Potions.WATER && PotionUtils.getEffectsFromStack(stack).isEmpty()) {
BlockRayTraceResult result = (BlockRayTraceResult) event.getRayTraceResult();
World world = entity.world;
Direction face = result.getFace();
BlockPos pos = result.getPos().offset(face);
extinguishLitBurners(world, pos, face);
extinguishLitBurners(world, pos.offset(face.getOpposite()), face);
for (Direction face1 : Direction.Plane.HORIZONTAL) {
extinguishLitBurners(world, pos.offset(face1), face1);
}
}
}
private static void extinguishLitBurners(World world, BlockPos pos, Direction direction) {
BlockState state = world.getBlockState(pos);
if (AllBlocks.LIT_BLAZE_BURNER.has(state)) {
world.playSound(null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
world.setBlockState(pos, AllBlocks.BLAZE_BURNER.getDefaultState());
}
}
} }