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

Add Powderbarrel and ITNT #2314

Merged
merged 8 commits into from
Jan 30, 2024
Merged
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
@@ -0,0 +1,81 @@
package gregtech.client.renderer.handler;

import gregtech.common.entities.EntityGTExplosive;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import org.jetbrains.annotations.NotNull;

@SideOnly(Side.CLIENT)
public class GTExplosiveRenderer<T extends EntityGTExplosive> extends Render<T> {

public GTExplosiveRenderer(RenderManager renderManager) {
super(renderManager);
this.shadowSize = 0.5F;
}

@Override
public void doRender(@NotNull T entity, double x, double y, double z, float entityYaw, float partialTicks) {
BlockRendererDispatcher brd = Minecraft.getMinecraft().getBlockRendererDispatcher();
GlStateManager.pushMatrix();
GlStateManager.translate((float) x, (float) y + 0.5F, (float) z);
float f2;
if ((float) entity.getFuse() - partialTicks + 1.0F < 10.0F) {
f2 = 1.0F - ((float) entity.getFuse() - partialTicks + 1.0F) / 10.0F;
f2 = MathHelper.clamp(f2, 0.0F, 1.0F);
f2 *= f2;
f2 *= f2;
float f1 = 1.0F + f2 * 0.3F;
GlStateManager.scale(f1, f1, f1);
}

f2 = (1.0F - ((float) entity.getFuse() - partialTicks + 1.0F) / 100.0F) * 0.8F;
this.bindEntityTexture(entity);
GlStateManager.rotate(-90.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.translate(-0.5F, -0.5F, 0.5F);

IBlockState state = entity.getExplosiveState();
brd.renderBlockBrightness(state, entity.getBrightness());
GlStateManager.translate(0.0F, 0.0F, 1.0F);
if (this.renderOutlines) {
GlStateManager.enableColorMaterial();
GlStateManager.enableOutlineMode(this.getTeamColor(entity));
brd.renderBlockBrightness(state, 1.0F);
GlStateManager.disableOutlineMode();
GlStateManager.disableColorMaterial();
} else if (entity.getFuse() / 5 % 2 == 0) {
GlStateManager.disableTexture2D();
GlStateManager.disableLighting();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.DST_ALPHA);
GlStateManager.color(1.0F, 1.0F, 1.0F, f2);
GlStateManager.doPolygonOffset(-3.0F, -3.0F);
GlStateManager.enablePolygonOffset();
brd.renderBlockBrightness(state, 1.0F);
GlStateManager.doPolygonOffset(0.0F, 0.0F);
GlStateManager.disablePolygonOffset();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableBlend();
GlStateManager.enableLighting();
GlStateManager.enableTexture2D();
}

GlStateManager.popMatrix();
super.doRender(entity, x, y, z, entityYaw, partialTicks);
}

@Override
protected ResourceLocation getEntityTexture(@NotNull T entity) {
return TextureMap.LOCATION_BLOCKS_TEXTURE;
}
}
4 changes: 4 additions & 0 deletions src/main/java/gregtech/common/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public static void registerBlocks(RegistryEvent.Register<Block> event) {
registry.register(RUBBER_WOOD_DOOR);
registry.register(TREATED_WOOD_DOOR);
registry.register(BRITTLE_CHARCOAL);
registry.register(POWDERBARREL);
registry.register(ITNT);
registry.register(METAL_SHEET);
registry.register(LARGE_METAL_SHEET);
registry.register(STUDS);
Expand Down Expand Up @@ -273,6 +275,8 @@ public static void registerItems(RegistryEvent.Register<Item> event) {
registry.register(createItemBlock(RUBBER_LOG, ItemBlock::new));
registry.register(createItemBlock(RUBBER_LEAVES, ItemBlock::new));
registry.register(createItemBlock(RUBBER_SAPLING, ItemBlock::new));
registry.register(createItemBlock(POWDERBARREL, ItemBlock::new));
registry.register(createItemBlock(ITNT, ItemBlock::new));

for (BlockCompressed block : COMPRESSED_BLOCKS) {
registry.register(createItemBlock(block, b -> new MaterialItemBlock(b, OrePrefix.block)));
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/gregtech/common/EventHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import gregtech.api.util.GTUtility;
import gregtech.api.util.VirtualTankRegistry;
import gregtech.api.worldgen.bedrockFluids.BedrockFluidVeinSaveData;
import gregtech.common.entities.EntityGTExplosive;
import gregtech.common.items.MetaItems;
import gregtech.common.items.armor.IStepAssist;
import gregtech.common.items.armor.PowerlessJetpack;
Expand All @@ -26,6 +27,7 @@
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -48,6 +50,7 @@
import net.minecraftforge.event.entity.player.AdvancementEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
import net.minecraftforge.event.world.ExplosionEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fml.common.Mod;
Expand Down Expand Up @@ -373,4 +376,13 @@ public static void onFurnaceFuelBurnTime(FurnaceFuelBurnTimeEvent event) {
event.setBurnTime(6400);
}
}

@SubscribeEvent
public static void onExplosionDetonate(ExplosionEvent.Detonate event) {
if (event.getExplosion().exploder instanceof EntityGTExplosive explosive) {
if (explosive.dropsAllBlocks()) {
event.getAffectedEntities().removeIf(entity -> entity instanceof EntityItem);
}
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/gregtech/common/MetaEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import gregtech.api.util.GTUtility;
import gregtech.client.renderer.handler.DynamiteRenderer;
import gregtech.client.renderer.handler.GTBoatRenderer;
import gregtech.client.renderer.handler.GTExplosiveRenderer;
import gregtech.client.renderer.handler.PortalRenderer;
import gregtech.common.entities.DynamiteEntity;
import gregtech.common.entities.GTBoatEntity;
import gregtech.common.entities.ITNTEntity;
import gregtech.common.entities.PortalEntity;
import gregtech.common.entities.PowderbarrelEntity;

import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
Expand All @@ -24,6 +27,10 @@ public static void init() {
GregTechAPI.instance, 64, 5, true);
EntityRegistry.registerModEntity(GTUtility.gregtechId("gtboat"), GTBoatEntity.class, "GTBoat", 3,
GregTechAPI.instance, 64, 2, true);
EntityRegistry.registerModEntity(GTUtility.gregtechId("powderbarrel"), PowderbarrelEntity.class, "Powderbarrel",
4, GregTechAPI.instance, 64, 3, true);
EntityRegistry.registerModEntity(GTUtility.gregtechId("itnt"), ITNTEntity.class, "ITNT", 5,
GregTechAPI.instance, 64, 3, true);
}

@SideOnly(Side.CLIENT)
Expand All @@ -32,5 +39,7 @@ public static void initRenderers() {
manager -> new DynamiteRenderer(manager, Minecraft.getMinecraft().getRenderItem()));
RenderingRegistry.registerEntityRenderingHandler(PortalEntity.class, PortalRenderer::new);
RenderingRegistry.registerEntityRenderingHandler(GTBoatEntity.class, GTBoatRenderer::new);
RenderingRegistry.registerEntityRenderingHandler(PowderbarrelEntity.class, GTExplosiveRenderer::new);
RenderingRegistry.registerEntityRenderingHandler(ITNTEntity.class, GTExplosiveRenderer::new);
}
}
10 changes: 10 additions & 0 deletions src/main/java/gregtech/common/blocks/MetaBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import gregtech.client.renderer.pipe.LaserPipeRenderer;
import gregtech.client.renderer.pipe.OpticalPipeRenderer;
import gregtech.common.ConfigHolder;
import gregtech.common.blocks.explosive.BlockITNT;
import gregtech.common.blocks.explosive.BlockPowderbarrel;
import gregtech.common.blocks.foam.BlockFoam;
import gregtech.common.blocks.foam.BlockPetrifiedFoam;
import gregtech.common.blocks.wood.BlockGregFence;
Expand Down Expand Up @@ -164,6 +166,8 @@ private MetaBlocks() {}
public static BlockFenceGate TREATED_WOOD_FENCE_GATE;
public static BlockWoodenDoor RUBBER_WOOD_DOOR;
public static BlockWoodenDoor TREATED_WOOD_DOOR;
public static BlockPowderbarrel POWDERBARREL;
public static BlockITNT ITNT;

public static BlockBrittleCharcoal BRITTLE_CHARCOAL;

Expand Down Expand Up @@ -312,6 +316,10 @@ public static void init() {
RUBBER_WOOD_DOOR.setRegistryName("rubber_wood_door").setTranslationKey("rubber_wood_door");
TREATED_WOOD_DOOR = new BlockWoodenDoor(() -> MetaItems.TREATED_WOOD_DOOR.getStackForm());
TREATED_WOOD_DOOR.setRegistryName("treated_wood_door").setTranslationKey("treated_wood_door");
POWDERBARREL = new BlockPowderbarrel();
POWDERBARREL.setRegistryName("powderbarrel").setTranslationKey("powderbarrel");
ITNT = new BlockITNT();
ITNT.setRegistryName("itnt").setTranslationKey("itnt");

BRITTLE_CHARCOAL = new BlockBrittleCharcoal();
BRITTLE_CHARCOAL.setRegistryName("brittle_charcoal");
Expand Down Expand Up @@ -481,6 +489,8 @@ public static void registerItemModels() {
new ModelResourceLocation(Objects.requireNonNull(TREATED_WOOD_FENCE_GATE.getRegistryName()),
"inventory"));
registerItemModel(BRITTLE_CHARCOAL);
registerItemModel(POWDERBARREL);
registerItemModel(ITNT);

registerItemModel(METAL_SHEET);
registerItemModel(LARGE_METAL_SHEET);
Expand Down
175 changes: 175 additions & 0 deletions src/main/java/gregtech/common/blocks/explosive/BlockGTExplosive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package gregtech.common.blocks.explosive;

import gregtech.common.creativetab.GTCreativeTabs;
import gregtech.common.entities.EntityGTExplosive;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

@SuppressWarnings("deprecation")
public abstract class BlockGTExplosive extends Block {

private final boolean canRedstoneActivate;
private final boolean explodeOnMine;
private final int fuseLength;

/**
* @param canRedstoneActivate whether redstone signal can prime this explosive
* @param explodeOnMine whether mining this block should prime it (sneak mine to drop normally)
* @param fuseLength explosion countdown after priming. Vanilla TNT is 80.
*/
public BlockGTExplosive(Material materialIn, boolean canRedstoneActivate, boolean explodeOnMine, int fuseLength) {
super(materialIn);
this.canRedstoneActivate = canRedstoneActivate;
this.explodeOnMine = explodeOnMine;
this.fuseLength = fuseLength;
setCreativeTab(GTCreativeTabs.TAB_GREGTECH_TOOLS);
}

protected abstract EntityGTExplosive createEntity(World world, BlockPos pos, EntityLivingBase exploder);

@Override
public float getExplosionResistance(@NotNull Entity exploder) {
return 1.0f;
}

@Override
public boolean canBeReplacedByLeaves(@NotNull IBlockState state, @NotNull IBlockAccess world,
@NotNull BlockPos pos) {
return false;
}

@Override
public boolean isNormalCube(@NotNull IBlockState state) {
return true;
}

@Override
public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos,
@NotNull EntityLiving.SpawnPlacementType type) {
return false;
}

@Override
public boolean canDropFromExplosion(@NotNull Explosion explosion) {
return false;
}

public void explode(World world, BlockPos pos, EntityLivingBase exploder) {
if (!world.isRemote) {
EntityGTExplosive entity = createEntity(world, pos, exploder);
entity.setFuse(fuseLength);
world.spawnEntity(entity);
world.playSound(null, entity.posX, entity.posY, entity.posZ, SoundEvents.ENTITY_TNT_PRIMED,
SoundCategory.BLOCKS, 1.0f, 1.0f);
}
}

@Override
public void onExplosionDestroy(@NotNull World world, @NotNull BlockPos pos, @NotNull Explosion explosion) {
if (!world.isRemote) {
EntityGTExplosive entity = createEntity(world, pos, explosion.getExplosivePlacedBy());
entity.setFuse(world.rand.nextInt(fuseLength / 4) + fuseLength / 8);
world.spawnEntity(entity);
}
}

@Override
public boolean onBlockActivated(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState state,
@NotNull EntityPlayer player, @NotNull EnumHand hand, @NotNull EnumFacing facing,
float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (!stack.isEmpty() && (stack.getItem() == Items.FLINT_AND_STEEL || stack.getItem() == Items.FIRE_CHARGE)) {
this.explode(world, pos, player);
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
if (stack.getItem() == Items.FLINT_AND_STEEL) {
stack.damageItem(1, player);
} else if (!player.capabilities.isCreativeMode) {
stack.shrink(1);
}
return true;
}
return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
}

@Override
public void dropBlockAsItemWithChance(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState state,
float chance, int fortune) {
if (explodeOnMine) {
EntityPlayer player = this.harvesters.get();
if (!player.isSneaking()) {
this.explode(world, pos, player);
return;
}
}
super.dropBlockAsItemWithChance(world, pos, state, chance, fortune);
}

@Override
public void onEntityCollision(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState state,
@NotNull Entity entity) {
if (!world.isRemote && entity instanceof EntityArrow arrow) {
if (arrow.isBurning()) {
this.explode(world, pos, arrow.shootingEntity instanceof EntityLivingBase living ? living : null);
world.setBlockToAir(pos);
}
}
}

@Override
public void onBlockAdded(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState state) {
super.onBlockAdded(world, pos, state);
if (canRedstoneActivate) {
if (world.isBlockPowered(pos)) {
explode(world, pos, null);
world.setBlockToAir(pos);
}
}
}

@Override
public void neighborChanged(@NotNull IBlockState state, @NotNull World world, @NotNull BlockPos pos,
@NotNull Block block, @NotNull BlockPos fromPos) {
if (canRedstoneActivate) {
if (world.isBlockPowered(pos)) {
explode(world, pos, null);
world.setBlockToAir(pos);
}
}
}

@Override
public void addInformation(@NotNull ItemStack stack, @Nullable World world, @NotNull List<String> tooltip,
@NotNull ITooltipFlag flag) {
if (explodeOnMine) {
tooltip.add(I18n.format("tile.gt_explosive.breaking_tooltip"));
}
if (!canRedstoneActivate) {
tooltip.add(I18n.format("tile.gt_explosive.lighting_tooltip"));
}
}
}
Loading
Loading