Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Utility of Gunpowder Barrel #5989

Draft
wants to merge 3 commits into
base: 1.20.4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

package blusunrize.immersiveengineering.client.render.entity;

import blusunrize.immersiveengineering.common.entities.IEExplosiveEntity;
import blusunrize.immersiveengineering.common.entities.GunpowderBarrelEntity;
import com.mojang.blaze3d.vertex.PoseStack;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
Expand All @@ -22,7 +21,7 @@
import net.minecraft.util.Mth;
import net.minecraft.world.inventory.InventoryMenu;

public class IEExplosiveRenderer extends EntityRenderer<IEExplosiveEntity>
public class IEExplosiveRenderer extends EntityRenderer<GunpowderBarrelEntity>
{
public IEExplosiveRenderer(Context renderManager)
{
Expand All @@ -31,7 +30,7 @@ public IEExplosiveRenderer(Context renderManager)
}

@Override
public void render(IEExplosiveEntity entity, float entityYaw, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn)
public void render(GunpowderBarrelEntity entity, float entityYaw, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn)
{
if(entity.block==null)
return;
Expand Down Expand Up @@ -63,7 +62,7 @@ public void render(IEExplosiveEntity entity, float entityYaw, float partialTicks
}

@Override
public ResourceLocation getTextureLocation(IEExplosiveEntity entity)
public ResourceLocation getTextureLocation(GunpowderBarrelEntity entity)
{
return InventoryMenu.BLOCK_ATLAS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@

public class EventHandler
{
public static Map<Level, Set<IEExplosion>> currentExplosions = new WeakHashMap<>();
public static final Queue<Runnable> SERVER_TASKS = new ArrayDeque<>();

@SubscribeEvent
Expand Down Expand Up @@ -175,19 +174,6 @@ public void onWorldTick(LevelTickEvent event)
if(next!=null)
next.run();
}

final Set<IEExplosion> explosionsInLevel = currentExplosions.get(event.level);
if(explosionsInLevel!=null)
{
Iterator<IEExplosion> itExplosion = explosionsInLevel.iterator();
while(itExplosion.hasNext())
{
IEExplosion ex = itExplosion.next();
ex.doExplosionTick();
if(ex.isExplosionFinished)
itExplosion.remove();
}
}
}

public static Map<UUID, Consumer<ItemStack>> crusherMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

package blusunrize.immersiveengineering.common.blocks.wooden;

import blusunrize.immersiveengineering.common.entities.IEExplosiveEntity;
import blusunrize.immersiveengineering.common.entities.GunpowderBarrelEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
Expand Down Expand Up @@ -51,7 +51,7 @@ public int getFlammability(BlockState state, BlockGetter world, BlockPos pos, Di
@Override
public void onCaughtFire(BlockState state, Level world, BlockPos pos, @org.jetbrains.annotations.Nullable Direction face, @org.jetbrains.annotations.Nullable LivingEntity igniter)
{
IEExplosiveEntity explosive = spawnExplosive(world, pos, state, igniter);
GunpowderBarrelEntity explosive = spawnExplosive(world, pos, state, igniter);
world.playSound(null, explosive.getX(), explosive.getY(), explosive.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
world.removeBlock(pos, false);
}
Expand All @@ -62,15 +62,14 @@ public void onBlockExploded(BlockState state, Level world, BlockPos pos, Explosi
super.onBlockExploded(state, world, pos, explosion);
if(!world.isClientSide)
{
IEExplosiveEntity explosive = spawnExplosive(world, pos, state, explosion.getIndirectSourceEntity());
GunpowderBarrelEntity explosive = spawnExplosive(world, pos, state, explosion.getIndirectSourceEntity());
explosive.setFuse((short)(world.random.nextInt(explosive.getFuse()/4)+explosive.getFuse()/8));
}
}

private IEExplosiveEntity spawnExplosive(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity igniter)
private GunpowderBarrelEntity spawnExplosive(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity igniter)
{
IEExplosiveEntity explosive = new IEExplosiveEntity(world, pos, igniter, state, 5);
explosive.setDropChance(1);
GunpowderBarrelEntity explosive = new GunpowderBarrelEntity(world, pos, igniter, state, 8);
world.addFreshEntity(explosive);
return explosive;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package blusunrize.immersiveengineering.common.entities;

import blusunrize.immersiveengineering.common.register.IEEntityTypes;
import blusunrize.immersiveengineering.common.util.IEExplosion;
import blusunrize.immersiveengineering.common.util.DirectionalMiningExplosion;
import blusunrize.immersiveengineering.mixin.accessors.TNTEntityAccess;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
Expand All @@ -35,24 +35,23 @@

import javax.annotation.Nonnull;

public class IEExplosiveEntity extends PrimedTnt
public class GunpowderBarrelEntity extends PrimedTnt
{
private float size;
private Explosion.BlockInteraction mode = BlockInteraction.DESTROY;
private boolean isFlaming = false;
private float explosionDropChance;
public BlockState block;
private Component name;

private static final EntityDataAccessor<BlockState> dataMarker_block = SynchedEntityData.defineId(IEExplosiveEntity.class, EntityDataSerializers.BLOCK_STATE);
private static final EntityDataAccessor<Integer> dataMarker_fuse = SynchedEntityData.defineId(IEExplosiveEntity.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<BlockState> dataMarker_block = SynchedEntityData.defineId(GunpowderBarrelEntity.class, EntityDataSerializers.BLOCK_STATE);
private static final EntityDataAccessor<Integer> dataMarker_fuse = SynchedEntityData.defineId(GunpowderBarrelEntity.class, EntityDataSerializers.INT);

public IEExplosiveEntity(EntityType<IEExplosiveEntity> type, Level world)
public GunpowderBarrelEntity(EntityType<GunpowderBarrelEntity> type, Level world)
{
super(type, world);
}

public IEExplosiveEntity(Level world, BlockPos pos, LivingEntity igniter, BlockState blockstate, float size)
public GunpowderBarrelEntity(Level world, BlockPos pos, LivingEntity igniter, BlockState blockstate, float size)
{
super(IEEntityTypes.EXPLOSIVE.get(), world);
this.setPos(pos.getX()+.5, pos.getY()+.5, pos.getZ()+.5);
Expand All @@ -65,28 +64,21 @@ public IEExplosiveEntity(Level world, BlockPos pos, LivingEntity igniter, BlockS
((TNTEntityAccess)this).setOwner(igniter);
this.size = size;
this.block = blockstate;
this.explosionDropChance = 1/size;
this.setBlockSynced();
}

public IEExplosiveEntity setMode(BlockInteraction smoke)
public GunpowderBarrelEntity setMode(BlockInteraction smoke)
{
this.mode = smoke;
return this;
}

public IEExplosiveEntity setFlaming(boolean fire)
public GunpowderBarrelEntity setFlaming(boolean fire)
{
this.isFlaming = fire;
return this;
}

public IEExplosiveEntity setDropChance(float chance)
{
this.explosionDropChance = chance;
return this;
}

@Override
protected void defineSynchedData()
{
Expand Down Expand Up @@ -172,12 +164,10 @@ public void tick()
}
int newFuse = this.getFuse()-1;
this.setFuse(newFuse);
if(newFuse <= 0)
if(newFuse < 0)
{
this.discard();

Explosion explosion = new IEExplosion(level(), this, getX(), getY()+(getBbHeight()/16f), getZ(), size, isFlaming, mode)
.setDropChance(explosionDropChance);
Explosion explosion = new DirectionalMiningExplosion(level(), this, getX(), getY()+(getBbHeight()/16f), getZ(), isFlaming);
if(!EventHooks.onExplosionStart(level(), explosion))
{
explosion.explode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.Holder;

import java.util.function.Supplier;

Expand All @@ -40,9 +39,9 @@ public class IEEntityTypes
() -> Builder.<FluorescentTubeEntity>of(FluorescentTubeEntity::new, MobCategory.MISC)
.sized(FluorescentTubeEntity.TUBE_LENGTH/2, 1+FluorescentTubeEntity.TUBE_LENGTH/2)
);
public static final DeferredHolder<EntityType<?>, EntityType<IEExplosiveEntity>> EXPLOSIVE = register(
public static final DeferredHolder<EntityType<?>, EntityType<GunpowderBarrelEntity>> EXPLOSIVE = register(
"explosive",
() -> Builder.<IEExplosiveEntity>of(IEExplosiveEntity::new, MobCategory.MISC)
() -> Builder.<GunpowderBarrelEntity>of(GunpowderBarrelEntity::new, MobCategory.MISC)
.fireImmune()
.sized(0.98F, 0.98F)
);
Expand Down
Loading
Loading