Configs, redstone fixes, concussive damage and more

This commit is contained in:
oitsjustjose 2022-10-18 11:06:01 -05:00
commit 466903d156
13 changed files with 284 additions and 153 deletions

View file

@ -1,16 +1,21 @@
package com.oitsjustjose.charged_explosives; package com.oitsjustjose.charged_explosives;
import com.oitsjustjose.charged_explosives.client.ClientProxy; import com.oitsjustjose.charged_explosives.client.ClientProxy;
import com.oitsjustjose.charged_explosives.client.config.ClientConfig;
import com.oitsjustjose.charged_explosives.common.CommonProxy; import com.oitsjustjose.charged_explosives.common.CommonProxy;
import com.oitsjustjose.charged_explosives.common.TickScheduler; import com.oitsjustjose.charged_explosives.common.TickScheduler;
import com.oitsjustjose.charged_explosives.common.config.CommonConfig;
import com.oitsjustjose.charged_explosives.common.registry.Registry; import com.oitsjustjose.charged_explosives.common.registry.Registry;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AddReloadListenerEvent; import net.minecraftforge.event.AddReloadListenerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -32,6 +37,7 @@ public class ChargedExplosives {
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(SCHEDULER); MinecraftForge.EVENT_BUS.register(SCHEDULER);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
this.configSetup();
} }
public static ChargedExplosives getInstance() { public static ChargedExplosives getInstance() {
@ -42,6 +48,13 @@ public class ChargedExplosives {
PROXY.init(); PROXY.init();
} }
private void configSetup() {
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, CommonConfig.COMMON_CONFIG);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ClientConfig.CLIENT_CONFIG);
CommonConfig.loadConfig(CommonConfig.COMMON_CONFIG, FMLPaths.CONFIGDIR.get().resolve(MODID + "-common.toml"));
ClientConfig.loadConfig(ClientConfig.CLIENT_CONFIG, FMLPaths.CONFIGDIR.get().resolve(MODID + "-client.toml"));
}
@SubscribeEvent @SubscribeEvent
public void onSlashReload(AddReloadListenerEvent evt) { public void onSlashReload(AddReloadListenerEvent evt) {
} }

View file

@ -39,14 +39,12 @@ public class ClientProxy extends CommonProxy {
public void startPreviewExplosion(Tuple<BlockPos, BlockPos> corners) { public void startPreviewExplosion(Tuple<BlockPos, BlockPos> corners) {
if(corners != null && corners.getA() != null && corners.getB() != null) { if(corners != null && corners.getA() != null && corners.getB() != null) {
bdRenderer.addExplosion(corners); bdRenderer.addExplosion(corners);
} }
} }
public void endPreviewExplosion(Tuple<BlockPos, BlockPos> corners) { public void endPreviewExplosion(Tuple<BlockPos, BlockPos> corners) {
if(corners != null && corners.getA() != null && corners.getB() != null) { if(corners != null && corners.getA() != null && corners.getB() != null) {
bdRenderer.removeExplosion(corners); bdRenderer.removeExplosion(corners);
} }
} }
} }

View file

@ -0,0 +1,35 @@
package com.oitsjustjose.charged_explosives.client.config;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.io.WritingMode;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.Builder;
import net.minecraftforge.fml.common.Mod;
import java.nio.file.Path;
@Mod.EventBusSubscriber
public class ClientConfig {
public static final ForgeConfigSpec CLIENT_CONFIG;
private static final Builder CLIENT_BUILDER = new Builder();
public static ForgeConfigSpec.BooleanValue ENABLE_EXPLOSION_PREVIEW_RENDER;
private static final String CATEGORY_CLIENT = "client_configs";
static {
init();
CLIENT_CONFIG = CLIENT_BUILDER.build();
}
public static void loadConfig(ForgeConfigSpec spec, Path path) {
final CommentedFileConfig configData = CommentedFileConfig.builder(path).sync().autosave().writingMode(WritingMode.REPLACE).build();
configData.load();
spec.setConfig(configData);
}
private static void init() {
CLIENT_BUILDER.comment("Client Configuration Settings").push(CATEGORY_CLIENT);
ENABLE_EXPLOSION_PREVIEW_RENDER = CLIENT_BUILDER.comment("Enable a red box showing which blocks will be destroyed?").define("enableExplosionPreviewRender", true);
CLIENT_BUILDER.pop();
}
}

View file

@ -4,6 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.oitsjustjose.charged_explosives.ChargedExplosives; import com.oitsjustjose.charged_explosives.ChargedExplosives;
import com.oitsjustjose.charged_explosives.common.Util; import com.oitsjustjose.charged_explosives.common.Util;
import com.oitsjustjose.charged_explosives.common.config.CommonConfig;
import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
@ -69,56 +70,60 @@ public class ExplosionConfigScreen extends Screen {
final int LW_MOD = 65; final int LW_MOD = 65;
final int EDIT_BOX_WIDTH = 40; final int EDIT_BOX_WIDTH = 40;
int rowWidth =/* Width of actual els */ INCR_W + DECR_W + EDIT_BOX_WIDTH int rowWidth =/* Width of actual els */ INCR_W + DECR_W + EDIT_BOX_WIDTH + (LW_MOD - EDIT_BOX_WIDTH) /* Offset for the left btn */ + (LW_MOD - EDIT_BOX_WIDTH - EB_MOD) /* Offset for the right btn */;
+ (LW_MOD - EDIT_BOX_WIDTH) /* Offset for the left btn */
+ (LW_MOD - EDIT_BOX_WIDTH - EB_MOD) /* Offset for the right btn */;
/* Width Adj */ /* Width Adj */
this.widthBox = this.addRenderableWidget(new EditBox(this.font, BG_X + ((rowWidth / 2) - 1) + EB_MOD, BG_Y + 40, EDIT_BOX_WIDTH, 20, Component.literal("")));
this.widthBox.setValue("" + this.explosionWidth);
this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + FW_MOD, BG_Y + 40, DECR_W, 20, DECR, onPress -> { this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + FW_MOD, BG_Y + 40, DECR_W, 20, DECR, onPress -> {
if (this.explosionWidth > 0) { if (this.explosionWidth > 1) {
this.explosionWidth--; this.explosionWidth--;
this.dirty = true; this.dirty = true;
this.widthBox.setValue("" + this.explosionWidth); this.widthBox.setValue("" + this.explosionWidth);
} }
})); }));
this.widthBox = this.addRenderableWidget(new EditBox(this.font, BG_X + ((rowWidth / 2) - 1) + EB_MOD, BG_Y + 40, EDIT_BOX_WIDTH, 20, Component.literal("")));
this.widthBox.setValue("" + this.explosionWidth);
this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + LW_MOD, BG_Y + 40, INCR_W, 20, INCR, onPress -> { this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + LW_MOD, BG_Y + 40, INCR_W, 20, INCR, onPress -> {
this.explosionWidth++; if (this.explosionWidth < CommonConfig.MAX_EXPLOSION_WIDTH.get()) {
this.dirty = true; this.explosionWidth++;
this.widthBox.setValue("" + this.explosionWidth); this.dirty = true;
this.widthBox.setValue("" + this.explosionWidth);
}
})); }));
/* Depth Adj */ /* Depth Adj */
this.depthBox = this.addRenderableWidget(new EditBox(this.font, BG_X + ((rowWidth / 2) - 1) + EB_MOD, BG_Y + 85, EDIT_BOX_WIDTH, 20, Component.literal("")));
this.depthBox.setValue("" + this.explosionDepth);
this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + FW_MOD, BG_Y + 85, DECR_W, 20, DECR, onPress -> { this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + FW_MOD, BG_Y + 85, DECR_W, 20, DECR, onPress -> {
if (this.explosionDepth > 0) { if (this.explosionDepth > 1) {
this.explosionDepth--; this.explosionDepth--;
this.dirty = true; this.dirty = true;
this.depthBox.setValue("" + this.explosionDepth); this.depthBox.setValue("" + this.explosionDepth);
} }
})); }));
this.depthBox = this.addRenderableWidget(new EditBox(this.font, BG_X + ((rowWidth / 2) - 1) + EB_MOD, BG_Y + 85, EDIT_BOX_WIDTH, 20, Component.literal("")));
this.depthBox.setValue("" + this.explosionDepth);
this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + LW_MOD, BG_Y + 85, INCR_W, 20, INCR, onPress -> { this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + LW_MOD, BG_Y + 85, INCR_W, 20, INCR, onPress -> {
this.explosionDepth++; if (this.explosionDepth < CommonConfig.MAX_EXPLOSION_DEPTH.get()) {
this.dirty = true; this.explosionDepth++;
this.depthBox.setValue("" + this.explosionDepth); this.dirty = true;
this.depthBox.setValue("" + this.explosionDepth);
}
})); }));
/* Height Adj */ /* Height Adj */
this.heightBox = this.addRenderableWidget(new EditBox(this.font, BG_X + ((rowWidth / 2) - 1) + EB_MOD, BG_Y + 130, EDIT_BOX_WIDTH, 20, Component.literal("")));
this.heightBox.setValue("" + this.explosionHeight);
this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + FW_MOD, BG_Y + 130, DECR_W, 20, DECR, onPress -> { this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + FW_MOD, BG_Y + 130, DECR_W, 20, DECR, onPress -> {
if (this.explosionHeight > 0) { if (this.explosionHeight > 1) {
this.explosionHeight--; this.explosionHeight--;
this.dirty = true; this.dirty = true;
this.heightBox.setValue("" + this.explosionHeight); this.heightBox.setValue("" + this.explosionHeight);
} }
})); }));
this.heightBox = this.addRenderableWidget(new EditBox(this.font, BG_X + ((rowWidth / 2) - 1) + EB_MOD, BG_Y + 130, EDIT_BOX_WIDTH, 20, Component.literal("")));
this.heightBox.setValue("" + this.explosionHeight);
this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + LW_MOD, BG_Y + 130, INCR_W, 20, INCR, onPress -> { this.addRenderableWidget(new Button(BG_X + ((rowWidth / 2) - 1) + LW_MOD, BG_Y + 130, INCR_W, 20, INCR, onPress -> {
this.explosionHeight++; if (this.explosionHeight < CommonConfig.MAX_EXPLOSION_HEIGHT.get()) {
this.dirty = true; this.explosionHeight++;
this.heightBox.setValue("" + this.explosionHeight); this.dirty = true;
this.heightBox.setValue("" + this.explosionHeight);
}
})); }));
} }
@ -142,10 +147,14 @@ public class ExplosionConfigScreen extends Screen {
try { try {
this.widthBox.tick(); this.widthBox.tick();
int value = Integer.parseInt(this.widthBox.getValue()); int value = Integer.parseInt(this.widthBox.getValue());
this.widthBox.setTextColor(WHITE); if (value <= 0 || value > CommonConfig.MAX_EXPLOSION_WIDTH.get()) {
if (value != explosionWidth) { this.widthBox.setTextColor(RED);
this.explosionWidth = value; } else {
this.dirty = true; this.widthBox.setTextColor(WHITE);
if (value != explosionWidth) {
this.explosionWidth = value;
this.dirty = true;
}
} }
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
this.widthBox.setTextColor(RED); this.widthBox.setTextColor(RED);
@ -154,10 +163,14 @@ public class ExplosionConfigScreen extends Screen {
try { try {
this.depthBox.tick(); this.depthBox.tick();
int value = Integer.parseInt(this.depthBox.getValue()); int value = Integer.parseInt(this.depthBox.getValue());
this.depthBox.setTextColor(WHITE); if (value <= 0 || value > CommonConfig.MAX_EXPLOSION_DEPTH.get()) {
if (value != explosionDepth) { this.depthBox.setTextColor(RED);
this.explosionDepth = value; } else {
this.dirty = true; this.depthBox.setTextColor(WHITE);
if (value != explosionDepth) {
this.explosionDepth = value;
this.dirty = true;
}
} }
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
this.depthBox.setTextColor(RED); this.depthBox.setTextColor(RED);
@ -166,29 +179,20 @@ public class ExplosionConfigScreen extends Screen {
try { try {
this.heightBox.tick(); this.heightBox.tick();
int value = Integer.parseInt(this.heightBox.getValue()); int value = Integer.parseInt(this.heightBox.getValue());
this.heightBox.setTextColor(WHITE); if (value <= 0 || value > CommonConfig.MAX_EXPLOSION_HEIGHT.get()) {
if (value != explosionHeight) { this.heightBox.setTextColor(RED);
this.explosionHeight = value; } else {
this.dirty = true; this.heightBox.setTextColor(WHITE);
if (value != explosionHeight) {
this.explosionHeight = value;
this.dirty = true;
}
} }
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
this.heightBox.setTextColor(RED); this.heightBox.setTextColor(RED);
} }
} }
private void tickEditBox(EditBox box, int comp, Function<Integer, Void> update) {
box.tick();
try {
int value = Integer.parseInt(box.getValue());
box.setTextColor(16777215);
if (value != comp) {
update.apply(value);
}
} catch (NumberFormatException ex) {
box.setTextColor(16711680);
}
}
@Override @Override
public boolean shouldCloseOnEsc() { public boolean shouldCloseOnEsc() {
return true; return true;
@ -226,6 +230,5 @@ public class ExplosionConfigScreen extends Screen {
@Override @Override
public void renderBackground(@NotNull PoseStack stack, int _unused) { public void renderBackground(@NotNull PoseStack stack, int _unused) {
this.fillGradient(stack, 0, 0, this.width, this.height, -1072689136, -804253680); this.fillGradient(stack, 0, 0, this.width, this.height, -1072689136, -804253680);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new ScreenEvent.BackgroundRendered(this, stack));
} }
} }

View file

@ -5,6 +5,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Matrix4f; import com.mojang.math.Matrix4f;
import com.oitsjustjose.charged_explosives.client.config.ClientConfig;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -13,7 +14,6 @@ import net.minecraft.world.phys.Vec3;
import net.minecraftforge.client.event.RenderLevelStageEvent; import net.minecraftforge.client.event.RenderLevelStageEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class BlockDestroyRenderer { public class BlockDestroyRenderer {
@ -29,7 +29,9 @@ public class BlockDestroyRenderer {
@SubscribeEvent @SubscribeEvent
public void renderWorldLastEvent(RenderLevelStageEvent event) { public void renderWorldLastEvent(RenderLevelStageEvent event) {
this.renderSelectedBlocks(event); if (ClientConfig.ENABLE_EXPLOSION_PREVIEW_RENDER.get()) {
this.renderSelectedBlocks(event);
}
} }
protected void renderSelectedBlocks(RenderLevelStageEvent event) { protected void renderSelectedBlocks(RenderLevelStageEvent event) {
@ -39,9 +41,7 @@ public class BlockDestroyRenderer {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
this.highlightedBlocks.stream().filter(x -> { this.highlightedBlocks.stream().filter(x -> x.getA().distToCenterSqr(mc.gameRenderer.getMainCamera().getPosition()) < 256D).forEach(pos -> {
return x.getA().distToCenterSqr(mc.gameRenderer.getMainCamera().getPosition()) < 256D;
}).forEach(pos -> {
PoseStack stack = event.getPoseStack(); PoseStack stack = event.getPoseStack();
MultiBufferSource.BufferSource buf = mc.renderBuffers().bufferSource(); MultiBufferSource.BufferSource buf = mc.renderBuffers().bufferSource();
VertexConsumer builder = buf.getBuffer(BlockOutlineRenderType.OVERLAY_LINES); VertexConsumer builder = buf.getBuffer(BlockOutlineRenderType.OVERLAY_LINES);

View file

@ -6,7 +6,6 @@ import net.minecraft.client.renderer.RenderType;
import java.util.OptionalDouble; import java.util.OptionalDouble;
public class BlockOutlineRenderType extends RenderType { public class BlockOutlineRenderType extends RenderType {
private static final LineStateShard THICK_LINES = new LineStateShard(OptionalDouble.of(4.0D)); private static final LineStateShard THICK_LINES = new LineStateShard(OptionalDouble.of(4.0D));
public static final RenderType OVERLAY_LINES = create("overlay_lines", public static final RenderType OVERLAY_LINES = create("overlay_lines",

View file

@ -6,6 +6,7 @@ import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.util.Set; import java.util.Set;
import java.util.UUID;
public class TickScheduler { public class TickScheduler {
protected Set<ScheduledTask> tasks = Sets.newConcurrentHashSet(); protected Set<ScheduledTask> tasks = Sets.newConcurrentHashSet();
@ -14,22 +15,29 @@ public class TickScheduler {
@SubscribeEvent @SubscribeEvent
public void registerEvent(TickEvent.ServerTickEvent event) { public void registerEvent(TickEvent.ServerTickEvent event) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
tasks.removeIf(x -> x.ready(now)); this.tasks.removeIf(x -> x.ready(now));
} }
public void addTask(ScheduledTask task) { public UUID addTask(ScheduledTask task) {
this.tasks.add(task); this.tasks.add(task);
return task.getUuid();
}
public void cancelTask(UUID uuid) {
this.tasks.removeIf(x -> x.uuid.equals(uuid));
} }
public static class ScheduledTask { public static class ScheduledTask {
public final Runnable exec; public final Runnable exec;
public final long startTime; public final long startTime;
public final int delayTimeSeconds; public final int delayTimeSeconds;
private final UUID uuid;
public ScheduledTask(Runnable exec, int delay) { public ScheduledTask(Runnable exec, int delay) {
this.exec = exec; this.exec = exec;
this.delayTimeSeconds = delay; this.delayTimeSeconds = delay;
this.startTime = System.currentTimeMillis(); this.startTime = System.currentTimeMillis();
this.uuid = UUID.randomUUID();
} }
public boolean ready(long time) { public boolean ready(long time) {
@ -37,5 +45,9 @@ public class TickScheduler {
if (ready) this.exec.run(); if (ready) this.exec.run();
return ready; return ready;
} }
public UUID getUuid() {
return this.uuid;
}
} }
} }

View file

@ -2,6 +2,7 @@ package com.oitsjustjose.charged_explosives.common.blocks;
import com.oitsjustjose.charged_explosives.ChargedExplosives; import com.oitsjustjose.charged_explosives.ChargedExplosives;
import com.oitsjustjose.charged_explosives.common.TickScheduler; import com.oitsjustjose.charged_explosives.common.TickScheduler;
import com.oitsjustjose.charged_explosives.common.config.CommonConfig;
import com.oitsjustjose.charged_explosives.common.tile.ChargedExplosiveBlockEntity; import com.oitsjustjose.charged_explosives.common.tile.ChargedExplosiveBlockEntity;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@ -10,12 +11,12 @@ import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
@ -26,8 +27,10 @@ import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.AttachFace; import net.minecraft.world.level.block.state.properties.AttachFace;
import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
@ -35,7 +38,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.concurrent.atomic.AtomicInteger; import java.util.List;
import java.util.Objects;
public class ChargedExplosiveBlock extends FaceAttachedHorizontalDirectionalBlock implements EntityBlock { public class ChargedExplosiveBlock extends FaceAttachedHorizontalDirectionalBlock implements EntityBlock {
@ -84,7 +88,7 @@ public class ChargedExplosiveBlock extends FaceAttachedHorizontalDirectionalBloc
} }
@Override @Override
public @NotNull VoxelShape getCollisionShape(BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull CollisionContext context) { public @NotNull VoxelShape getCollisionShape(@NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull CollisionContext context) {
return this.getShape(state, level, pos, context); return this.getShape(state, level, pos, context);
} }
@ -104,17 +108,23 @@ public class ChargedExplosiveBlock extends FaceAttachedHorizontalDirectionalBloc
be.load(tag); be.load(tag);
if (placer.getOffhandItem().getItem() == Items.REDSTONE_TORCH) { if (placer.getOffhandItem().getItem() == Items.REDSTONE_TORCH) {
this.explode(level, pos); this.explode(level, pos);
} else if (level.hasNeighborSignal(pos)) {
this.explode(level, pos);
} }
} }
@Override @Override
public void onRemove(BlockState oldState, @NotNull Level level, @NotNull BlockPos pos, BlockState newState, boolean moving) { public void onRemove(@NotNull BlockState oldState, @NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState newState, boolean moving) {
if (!newState.is(oldState.getBlock())) { if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity cebe) {
if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity cebe) { ChargedExplosives.getInstance().PROXY.endPreviewExplosion(cebe.getCorners());
ChargedExplosives.getInstance().PROXY.endPreviewExplosion(cebe.getCorners()); ItemStack stack = new ItemStack(ChargedExplosives.getInstance().REGISTRY.CeItem.get());
} cebe.saveToItem(stack);
level.removeBlockEntity(pos); ItemEntity ent = new ItemEntity(level, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, stack);
ent.setDefaultPickUpDelay();
level.addFreshEntity(ent);
} }
level.removeBlockEntity(pos);
super.onRemove(oldState, level, pos, newState, moving); super.onRemove(oldState, level, pos, newState, moving);
} }
@ -125,55 +135,26 @@ public class ChargedExplosiveBlock extends FaceAttachedHorizontalDirectionalBloc
} }
@Override @Override
// TODO: apply same logic if block is just *poof'd* public @NotNull InteractionResult use(@Nonnull BlockState state, @Nonnull Level level, @Nonnull BlockPos pos, @Nonnull Player player, @Nonnull InteractionHand hand, @Nonnull BlockHitResult hit) {
public void playerWillDestroy(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull Player player) {
if (player.isCreative()) {
return;
}
BlockEntity be = level.getBlockEntity(pos);
if (be instanceof ChargedExplosiveBlockEntity expBe) {
ItemStack stack = new ItemStack(ChargedExplosives.getInstance().REGISTRY.CeItem.get());
expBe.saveToItem(stack);
ItemEntity ent = new ItemEntity(level, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, stack);
ent.setDefaultPickUpDelay();
level.addFreshEntity(ent);
}
// TODO (MAYBE): ability to store upcoming tasks for this tile entity and cancel them on break
}
@Override
public InteractionResult use(@Nonnull BlockState state, @Nonnull Level level, @Nonnull BlockPos pos, @Nonnull Player player, @Nonnull InteractionHand hand, @Nonnull BlockHitResult hit) {
if (level.isClientSide()) { if (level.isClientSide()) {
player.swing(hand); player.swing(hand);
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
explode(level, pos); this.explode(level, pos);
return InteractionResult.CONSUME; return InteractionResult.CONSUME;
} }
@Override @Override
public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) { public void neighborChanged(@NotNull BlockState state, Level level, @NotNull BlockPos pos, @NotNull Block block, @NotNull BlockPos fromPos, boolean isMoving) {
if (level.hasNeighborSignal(pos)) { if (level.hasNeighborSignal(pos)) {
if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity cebe) { if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity cebe) {
if (!cebe.hasBeenActivated()) { if (!cebe.hasBeenActivated()) {
cebe.setActivated(); this.explode(level, pos);
explode(level, pos);
} }
} }
} }
} }
@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
if (ctx.getLevel().hasNeighborSignal(ctx.getClickedPos())) {
this.explode(ctx.getLevel(), ctx.getClickedPos());
}
return super.getStateForPlacement(ctx);
// return (BlockState)this\.defaultBlockState().setValue(LIT, p_55659_.getLevel().hasNeighborSignal(p_55659_.getClickedPos()));
}
private void explode(Level level, BlockPos pos) { private void explode(Level level, BlockPos pos) {
if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity cebe) { if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity cebe) {
if (cebe.hasBeenActivated()) { if (cebe.hasBeenActivated()) {
@ -181,32 +162,32 @@ public class ChargedExplosiveBlock extends FaceAttachedHorizontalDirectionalBloc
} else { } else {
cebe.setActivated(); cebe.setActivated();
} }
cebe.addScheduledTask(ChargedExplosives.getInstance().SCHEDULER.addTask(new TickScheduler.ScheduledTask(() -> this.explodeTask(level, pos), CommonConfig.EXPLOSION_COUNTDOWN_TIME.get())));
for (int i = 0; i < CommonConfig.NUM_BEEPS.get(); i++) {
cebe.addScheduledTask(ChargedExplosives.getInstance().SCHEDULER.addTask(new TickScheduler.ScheduledTask(() -> {
if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity) { // check that it's still there
level.playSound(null, pos, ChargedExplosives.getInstance().REGISTRY.BeepBoop.get(), SoundSource.BLOCKS, 0.5F, 1.0F);
}
}, (CommonConfig.EXPLOSION_COUNTDOWN_TIME.get() / CommonConfig.NUM_BEEPS.get()) * i)));
}
} }
// TODO: configs
final int DELAY_TIME_SECONDS = 5;
final int NUM_WARNING_BEEPS = 5;
ChargedExplosives.getInstance().SCHEDULER.addTask(new TickScheduler.ScheduledTask(() -> this.explodeTask(level, pos), DELAY_TIME_SECONDS));
for (int i = 0; i < NUM_WARNING_BEEPS; i++) {
ChargedExplosives.getInstance().SCHEDULER.addTask(new TickScheduler.ScheduledTask(
() -> {
if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity) { // check that it's still there
level.playSound(null, pos, ChargedExplosives.getInstance().REGISTRY.BeepBoop.get(), SoundSource.BLOCKS, 0.5F, 1.0F);
}
},
(DELAY_TIME_SECONDS / NUM_WARNING_BEEPS) * i
));
}
} }
private void explodeTask(Level level, BlockPos pos) { private void explodeTask(Level level, BlockPos pos) {
if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity cebe) { if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity cebe) {
/* ↥ WARNING: the below block will *destroy* cebe, so anything using should go here ↥ */ /* ↥ WARNING: the below block will *destroy* cebe, so anything using should go here ↥ */
AtomicInteger explodedCount = new AtomicInteger();
level.playSound(null, pos, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 1.0F, 1.0F);
ChargedExplosives.getInstance().PROXY.endPreviewExplosion(cebe.getCorners());
level.removeBlockEntity(pos);
level.removeBlock(pos, false);
AABB aabb = new AABB(cebe.getCorners().getA(), cebe.getCorners().getB()).inflate(5.0D);
float dmgAmt = cebe.calculateConcussiveDamage();
cebe.getExplosions().forEach(p -> { cebe.getExplosions().forEach(p -> {
BlockState state = level.getBlockState(p); BlockState state = level.getBlockState(p);
if (!state.hasBlockEntity()) { if (!state.hasBlockEntity()) {
@ -215,22 +196,15 @@ public class ChargedExplosiveBlock extends FaceAttachedHorizontalDirectionalBloc
level.removeBlock(p, false); level.removeBlock(p, false);
/* Ignore the yellow squiggles below - p_49886 is passed to a func where it's Nullable */ /* Ignore the yellow squiggles below - p_49886 is passed to a func where it's Nullable */
Block.dropResources(state, level, p, null, null, ItemStack.EMPTY); Block.dropResources(state, level, p, null, null, ItemStack.EMPTY);
explodedCount.getAndIncrement();
if (level.getRandom().nextBoolean()) { if (level.getRandom().nextBoolean()) {
ChargedExplosives.getInstance().PROXY.spawnExplosionParticle(p); ChargedExplosives.getInstance().PROXY.spawnExplosionParticle(p);
} }
} }
} }
}); });
List<LivingEntity> entities = level.getEntities(EntityTypeTest.forClass(LivingEntity.class), aabb, Objects::nonNull);
entities.forEach(x -> x.hurt(DamageSource.GENERIC, dmgAmt));
// TODO: if explosion doesn't happen, make a new sound
if (explodedCount.get() > 0) {
level.playSound(null, pos, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 1.0F, 1.0F);
ChargedExplosives.getInstance().PROXY.endPreviewExplosion(cebe.getCorners());
level.removeBlockEntity(pos);
level.removeBlock(pos, false);
}
} }
} }
} }

View file

@ -0,0 +1,55 @@
package com.oitsjustjose.charged_explosives.common.config;
import java.nio.file.Path;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.io.WritingMode;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.Builder;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber
public class CommonConfig {
public static final ForgeConfigSpec COMMON_CONFIG;
private static final Builder COMMON_BUILDER = new Builder();
public static ForgeConfigSpec.DoubleValue CONCUSSIVE_DAMAGE_SCALE;
public static ForgeConfigSpec.IntValue MAX_EXPLOSION_WIDTH;
public static ForgeConfigSpec.IntValue MAX_EXPLOSION_HEIGHT;
public static ForgeConfigSpec.IntValue MAX_EXPLOSION_DEPTH;
public static ForgeConfigSpec.IntValue EXPLOSION_COUNTDOWN_TIME;
public static ForgeConfigSpec.IntValue NUM_BEEPS;
private static final String CATEGORY_MISC = "common_configuration";
static {
init();
COMMON_CONFIG = COMMON_BUILDER.build();
}
public static void loadConfig(ForgeConfigSpec spec, Path path) {
final CommentedFileConfig configData = CommentedFileConfig.builder(path).sync().autosave()
.writingMode(WritingMode.REPLACE).build();
configData.load();
spec.setConfig(configData);
}
private static void init() {
COMMON_BUILDER.comment("Miscellaneous").push(CATEGORY_MISC);
CONCUSSIVE_DAMAGE_SCALE = COMMON_BUILDER.comment("A percentage (decimal from 0-1) of how much concussive damage should be done by charges. 0 disables concussive damage.",
"Values greater than 0 will hurt anything in a radius of the blast by an amount (calculated by the explosive's width, depth and height) times this value.")
.defineInRange("concussiveDamageScale", 0.1, 0.0, 1.0);
MAX_EXPLOSION_WIDTH = COMMON_BUILDER.comment("The max explosion width a user can set in their explosive").defineInRange("maxExplosionWidth", 11, 1, 128);
MAX_EXPLOSION_HEIGHT = COMMON_BUILDER.comment("The max explosion height a user can set in their explosive").defineInRange("maxExplosionHeight", 11, 1, 128);
MAX_EXPLOSION_DEPTH = COMMON_BUILDER.comment("The max explosion depth a user can set in their explosive").defineInRange("maxExplosionDepth", 11, 1, 128);
EXPLOSION_COUNTDOWN_TIME = COMMON_BUILDER.comment("The amount of time between activating an explosive and when it detonates, in seconds. Setting to 0 makes it instant")
.defineInRange("detonationCountdownTime", 5, 0, Integer.MAX_VALUE);
NUM_BEEPS=COMMON_BUILDER.comment("The number of warning beeps given after setting an explosive off to detonate. Time is distributed evenly across the value configured in 'detonationCountdownTime'")
.defineInRange("detonationBeepCount", 5, 0, Integer.MAX_VALUE);
COMMON_BUILDER.pop();
}
}

View file

@ -3,6 +3,7 @@ package com.oitsjustjose.charged_explosives.common.items;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.oitsjustjose.charged_explosives.ChargedExplosives; import com.oitsjustjose.charged_explosives.ChargedExplosives;
import com.oitsjustjose.charged_explosives.common.Util; import com.oitsjustjose.charged_explosives.common.Util;
import com.oitsjustjose.charged_explosives.common.config.CommonConfig;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@ -40,52 +41,70 @@ public class ChargedExplosiveItem extends BlockItem {
return super.use(level, player, hand); return super.use(level, player, hand);
} }
public static boolean isNbtInvalid(ItemStack stack) { public static boolean isNbtInitialized(ItemStack stack) {
if (stack.hasTag()) { if (stack.hasTag()) {
CompoundTag tag = Objects.requireNonNull(stack.getTag()); CompoundTag tag = Objects.requireNonNull(stack.getTag());
return !tag.contains("explosionWidth") || !tag.contains("explosionHeight") || !tag.contains("explosionDepth"); return tag.contains("explosionWidth") && tag.contains("explosionHeight") && tag.contains("explosionDepth");
} }
return true; return false;
}
public static boolean isNbtValid(ItemStack stack) {
if (stack.hasTag() && isNbtInitialized(stack)) {
CompoundTag tag = Objects.requireNonNull(stack.getTag());
int w = tag.getInt("explosionWidth");
int h = tag.getInt("explosionHeight");
int d = tag.getInt("explosionDepth");
boolean zeroCheck = w > 0 && h > 0 && d > 0;
boolean configCheck = w <= CommonConfig.MAX_EXPLOSION_WIDTH.get() && h <= CommonConfig.MAX_EXPLOSION_HEIGHT.get() && d <= CommonConfig.MAX_EXPLOSION_DEPTH.get();
return zeroCheck && configCheck;
}
return false;
} }
@Override @Override
public @NotNull InteractionResult place(BlockPlaceContext context) { public @NotNull InteractionResult place(BlockPlaceContext context) {
ItemStack stack = context.getItemInHand(); ItemStack stack = context.getItemInHand();
if (isNbtInvalid(stack)) { // TODO: noises
if (!isNbtInitialized(stack)) {
Objects.requireNonNull(context.getPlayer()).displayClientMessage(Util.translateOrFallback(ChargedExplosives.MODID + ".needs_init"), true); Objects.requireNonNull(context.getPlayer()).displayClientMessage(Util.translateOrFallback(ChargedExplosives.MODID + ".needs_init"), true);
return InteractionResult.FAIL; return InteractionResult.FAIL;
} }
if (!isNbtValid(stack)) {
Objects.requireNonNull(context.getPlayer()).displayClientMessage(Util.translateOrFallback(ChargedExplosives.MODID + ".invalid_config"), true);
return InteractionResult.FAIL;
}
return super.place(context); return super.place(context);
} }
@Override @Override
protected boolean updateCustomBlockEntityTag(@Nonnull BlockPos p, @Nonnull Level l, @Nullable Player pl, @Nonnull ItemStack s, @Nonnull BlockState st) { protected boolean updateCustomBlockEntityTag(@Nonnull BlockPos p, @Nonnull Level l, @Nullable Player pl, @Nonnull ItemStack s, @Nonnull BlockState st) {
return true; return false;
} }
@Override @Override
public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level, @NotNull List<Component> components, @NotNull TooltipFlag flag) { public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level, @NotNull List<Component> components, @NotNull TooltipFlag flag) {
if (!stack.hasTag()) { if (!isNbtInitialized(stack)) {
components.add(Util.translateOrFallback(ChargedExplosives.MODID + ".needs_init_tooltip"));
return;
}
if (!isNbtValid(stack)) {
components.add(Util.translateOrFallback(ChargedExplosives.MODID + ".invalid_configuration_tooltip"));
return; return;
} }
CompoundTag tag = Objects.requireNonNull(stack.getTag()); CompoundTag tag = Objects.requireNonNull(stack.getTag());
if (isNbtInvalid(stack)) { int w = tag.getInt("explosionWidth");
components.add(Util.translateOrFallback(ChargedExplosives.MODID + ".not_yet_initialized")); int d = tag.getInt("explosionDepth");
return; int h = tag.getInt("explosionHeight");
} else { try {
int w = tag.getInt("explosionWidth"); TranslatableContents wc = new TranslatableContents(ChargedExplosives.MODID + ".width_tooltip", w);
int d = tag.getInt("explosionDepth"); components.add(wc.resolve(null, null, 0));
int h = tag.getInt("explosionHeight"); TranslatableContents dc = new TranslatableContents(ChargedExplosives.MODID + ".depth_tooltip", d);
try { components.add(dc.resolve(null, null, 0));
TranslatableContents wc = new TranslatableContents(ChargedExplosives.MODID + ".width_tooltip", w); TranslatableContents hc = new TranslatableContents(ChargedExplosives.MODID + ".height_tooltip", h);
components.add(wc.resolve(null, null, 0)); components.add(hc.resolve(null, null, 0));
TranslatableContents dc = new TranslatableContents(ChargedExplosives.MODID + ".depth_tooltip", d); } catch (CommandSyntaxException ignored) {
components.add(dc.resolve(null, null, 0));
TranslatableContents hc = new TranslatableContents(ChargedExplosives.MODID + ".height_tooltip", h);
components.add(hc.resolve(null, null, 0));
} catch (CommandSyntaxException ignored) {
}
} }
} }
} }

View file

@ -1,6 +1,7 @@
package com.oitsjustjose.charged_explosives.common.tile; package com.oitsjustjose.charged_explosives.common.tile;
import com.oitsjustjose.charged_explosives.ChargedExplosives; import com.oitsjustjose.charged_explosives.ChargedExplosives;
import com.oitsjustjose.charged_explosives.common.config.CommonConfig;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -11,8 +12,10 @@ import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.AttachFace; import net.minecraft.world.level.block.state.properties.AttachFace;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID;
public class ChargedExplosiveBlockEntity extends BlockEntity { public class ChargedExplosiveBlockEntity extends BlockEntity {
private int explosionWidth = 0; private int explosionWidth = 0;
@ -20,11 +23,13 @@ public class ChargedExplosiveBlockEntity extends BlockEntity {
private int explosionDepth = 0; private int explosionDepth = 0;
private boolean goingOffNow = false; private boolean goingOffNow = false;
private ArrayList<BlockPos> explosionPositions; private ArrayList<BlockPos> explosionPositions;
private final ArrayList<UUID> scheduledTasks;
private Tuple<BlockPos, BlockPos> cornerToCorner; private Tuple<BlockPos, BlockPos> cornerToCorner;
public ChargedExplosiveBlockEntity(BlockPos pos, BlockState state) { public ChargedExplosiveBlockEntity(BlockPos pos, BlockState state) {
super(ChargedExplosives.getInstance().REGISTRY.CeBlockEntityType.get(), pos, state); super(ChargedExplosives.getInstance().REGISTRY.CeBlockEntityType.get(), pos, state);
this.explosionPositions = new ArrayList<>(); this.explosionPositions = new ArrayList<>();
this.scheduledTasks = new ArrayList<>();
} }
@Override @Override
@ -35,7 +40,7 @@ public class ChargedExplosiveBlockEntity extends BlockEntity {
} }
@Override @Override
public void load(CompoundTag tag) { public void load(@NotNull CompoundTag tag) {
super.load(tag); super.load(tag);
this.explosionWidth = tag.getInt("explosionWidth"); this.explosionWidth = tag.getInt("explosionWidth");
this.explosionHeight = tag.getInt("explosionHeight"); this.explosionHeight = tag.getInt("explosionHeight");
@ -51,7 +56,13 @@ public class ChargedExplosiveBlockEntity extends BlockEntity {
tag.putInt("explosionWidth", explosionWidth); tag.putInt("explosionWidth", explosionWidth);
tag.putInt("explosionHeight", explosionHeight); tag.putInt("explosionHeight", explosionHeight);
tag.putInt("explosionDepth", explosionDepth); tag.putInt("explosionDepth", explosionDepth);
super.saveToItem(stack); }
public float calculateConcussiveDamage() {
return (((float) this.explosionWidth / (CommonConfig.MAX_EXPLOSION_WIDTH.get() / 2F)) +
((float) this.explosionHeight / (CommonConfig.MAX_EXPLOSION_HEIGHT.get() / 2F)) +
((float) this.explosionDepth / (CommonConfig.MAX_EXPLOSION_DEPTH.get() / 2F))) *
CommonConfig.CONCUSSIVE_DAMAGE_SCALE.get().floatValue();
} }
public ArrayList<BlockPos> getExplosions() { public ArrayList<BlockPos> getExplosions() {
@ -124,7 +135,6 @@ public class ChargedExplosiveBlockEntity extends BlockEntity {
endZ = pos.getZ() + (int) Math.ceil(explosionWidth / 2F); endZ = pos.getZ() + (int) Math.ceil(explosionWidth / 2F);
} }
default -> { default -> {
break;
} }
} }
} }
@ -166,4 +176,14 @@ public class ChargedExplosiveBlockEntity extends BlockEntity {
public void setActivated() { public void setActivated() {
this.goingOffNow = true; this.goingOffNow = true;
} }
public void addScheduledTask(UUID uuid) {
this.scheduledTasks.add(uuid);
}
@Override
public void setRemoved() {
this.scheduledTasks.forEach(ChargedExplosives.getInstance().SCHEDULER::cancelTask);
super.setRemoved();
}
} }

View file

@ -3,11 +3,13 @@
"charged_explosives.explosion.width.title": "Explosion Width:", "charged_explosives.explosion.width.title": "Explosion Width:",
"charged_explosives.explosion.height.title": "Explosion Height:", "charged_explosives.explosion.height.title": "Explosion Height:",
"charged_explosives.explosion.depth.title": "Explosion Depth:", "charged_explosives.explosion.depth.title": "Explosion Depth:",
"charged_explosives.not_yet_initialized": "§8Unconfigured§r", "charged_explosives.needs_init_tooltip": "§8Unconfigured§r",
"charged_explosives.invalid_configuration_tooltip": "§8Invalid Config§r",
"charged_explosives.width_tooltip": " §8Width: §8%s§r", "charged_explosives.width_tooltip": " §8Width: §8%s§r",
"charged_explosives.depth_tooltip": " §8Depth: §8%s§r", "charged_explosives.depth_tooltip": " §8Depth: §8%s§r",
"charged_explosives.height_tooltip": " §8Height: §8%s§r", "charged_explosives.height_tooltip": " §8Height: §8%s§r",
"charged_explosives.needs_init": "This Explosive Needs to be Configured", "charged_explosives.needs_init": "Explosive Needs to be Configured",
"charged_explosives.invalid_config": "Explosive Has Invalid Configuration",
"charge.beep.boops": "§cCharged Explosive Beeps Aggressively§r", "charge.beep.boops": "§cCharged Explosive Beeps Aggressively§r",
"block.charged_explosives.charged_explosive": "Explosive Charge" "block.charged_explosives.charged_explosive": "Explosive Charge"
} }

View file

@ -36,8 +36,9 @@
], ],
"display": { "display": {
"thirdperson_righthand": { "thirdperson_righthand": {
"translation": [0, 3, 1], "rotation": [65, 0, 0],
"scale": [0.55, 0.55, 0.55] "translation": [0, 3, 4.75],
"scale": [0.75, 0.75, 0.75]
}, },
"thirdperson_lefthand": { "thirdperson_lefthand": {
"rotation": [65, 0, 0], "rotation": [65, 0, 0],