From bdbd5c9533d83d6df90bd1b28e1440bad105a181 Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Thu, 8 Jul 2021 23:21:51 -0700 Subject: [PATCH] Remote extinguishing - Make splash water bottles extinguish lit blaze burners --- .../processing/burner/BlazeBurnerHandler.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerHandler.java b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerHandler.java index 07582c253..3b37c7ef7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerHandler.java @@ -1,11 +1,24 @@ package com.simibubi.create.content.contraptions.processing.burner; +import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSoundEvents; 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.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.util.Direction; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvents; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.vector.Vector3d; @@ -18,6 +31,11 @@ import net.minecraftforge.fml.common.Mod; public class BlazeBurnerHandler { @SubscribeEvent + public static void onThrowableImpact(ProjectileImpactEvent.Throwable event) { + thrownEggsGetEatenByBurner(event); + splashExtinguishesBurner(event); + } + public static void thrownEggsGetEatenByBurner(ProjectileImpactEvent.Throwable event) { if (!(event.getThrowable() instanceof EggEntity)) return; @@ -54,4 +72,41 @@ public class BlazeBurnerHandler { 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()); + } + } + }