beeps, boops, countdown times and more!

This commit is contained in:
oitsjustjose 2022-10-17 23:44:12 -05:00
commit b005707d14
17 changed files with 221 additions and 105 deletions

View file

@ -2,6 +2,7 @@ package com.oitsjustjose.charged_explosives;
import com.oitsjustjose.charged_explosives.client.ClientProxy;
import com.oitsjustjose.charged_explosives.common.CommonProxy;
import com.oitsjustjose.charged_explosives.common.TickScheduler;
import com.oitsjustjose.charged_explosives.common.registry.Registry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AddReloadListenerEvent;
@ -19,14 +20,17 @@ public class ChargedExplosives {
public static final String MODID = "charged_explosives";
public final Logger LOGGER = LogManager.getLogger();
public final Registry REGISTRY = new Registry();
public final CommonProxy proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);
public final CommonProxy PROXY = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);
public final TickScheduler SCHEDULER = new TickScheduler();
public ChargedExplosives() {
instance = this;
REGISTRY.BlockRegistry.register(FMLJavaModLoadingContext.get().getModEventBus());
REGISTRY.ItemRegistry.register(FMLJavaModLoadingContext.get().getModEventBus());
REGISTRY.BlockEntityTypeRegistry.register(FMLJavaModLoadingContext.get().getModEventBus());
REGISTRY.SoundEventRegistry.register(FMLJavaModLoadingContext.get().getModEventBus());
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(SCHEDULER);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
}
@ -35,7 +39,7 @@ public class ChargedExplosives {
}
public void setup(final FMLCommonSetupEvent evt) {
proxy.init();
PROXY.init();
}
@SubscribeEvent

View file

@ -9,15 +9,11 @@ import com.oitsjustjose.charged_explosives.common.network.ExplosionParticlePacke
import com.oitsjustjose.charged_explosives.common.network.OpenGuiPacket;
import com.oitsjustjose.charged_explosives.common.network.PreviewExplosionPacket;
import com.oitsjustjose.charged_explosives.common.network.UpdateNbtPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.Tuple;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.PacketDistributor;
import java.util.Optional;
@ -40,31 +36,17 @@ public class ClientProxy extends CommonProxy {
CommonProxy.netMgr.networkWrapper.sendToServer(pkt);
}
public void openExplosiveGui(Player player, ItemStack stack) {
super.openExplosiveGui(player, stack);
}
@Override
public void startPreviewExplosion(Tuple<BlockPos, BlockPos> corners) {
bdRenderer.addExplosion(corners);
// super.startPreviewExplosion(corners);
if(corners != null && corners.getA() != null && corners.getB() != null) {
bdRenderer.addExplosion(corners);
}
}
@Override
public void endPreviewExplosion(Tuple<BlockPos, BlockPos> corners) {
bdRenderer.removeExplosion(corners);
// super.endPreviewExplosion(corners);
}
if(corners != null && corners.getA() != null && corners.getB() != null) {
bdRenderer.removeExplosion(corners);
public void spawnExplosionParticle(BlockPos pos) {
if (Minecraft.getInstance().level != null) {
Minecraft.getInstance().level.addParticle(
ParticleTypes.EXPLOSION,
(double) pos.getX() + 0.5D,
(double) pos.getY() + 0.5D,
(double) pos.getZ() + 0.5D,
1.0D, 0.0D, 0.0D
);
}
}
}

View file

@ -129,7 +129,7 @@ public class ExplosionConfigScreen extends Screen {
tag.putInt("explosionWidth", explosionWidth);
tag.putInt("explosionDepth", explosionDepth);
tag.putInt("explosionHeight", explosionHeight);
ChargedExplosives.getInstance().proxy.updateItemNbt(stack);
ChargedExplosives.getInstance().PROXY.updateItemNbt(stack);
}
super.onClose();
}

View file

@ -10,6 +10,9 @@ import java.util.function.Supplier;
public class ClientExplosionParticlePacket {
public static void handleClient(ExplosionParticlePacket pkt, Supplier<NetworkEvent.Context> ctx) {
double e = 1.5D;
double f = 10.0D;
double g = 0.0D;
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
ctx.get().enqueueWork(() -> {
if (Minecraft.getInstance().level != null) {
@ -18,7 +21,7 @@ public class ClientExplosionParticlePacket {
(double) pkt.pos.getX() + 0.5D,
(double) pkt.pos.getY() + 0.5D,
(double) pkt.pos.getZ() + 0.5D,
1.0D, 0.0D, 0.0D
e,f,g
);
}
});

View file

@ -0,0 +1,41 @@
package com.oitsjustjose.charged_explosives.common;
import com.google.common.collect.Sets;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.util.Set;
public class TickScheduler {
protected Set<ScheduledTask> tasks = Sets.newConcurrentHashSet();
@SubscribeEvent
public void registerEvent(TickEvent.ServerTickEvent event) {
long now = System.currentTimeMillis();
tasks.removeIf(x -> x.ready(now));
}
public void addTask(ScheduledTask task) {
this.tasks.add(task);
}
public static class ScheduledTask {
public final Runnable exec;
public final long startTime;
public final int delayTimeSeconds;
public ScheduledTask(Runnable exec, int delay) {
this.exec = exec;
this.delayTimeSeconds = delay;
this.startTime = System.currentTimeMillis();
}
public boolean ready(long time) {
boolean ready = time - startTime >= (delayTimeSeconds * 1000L);
if (ready) this.exec.run();
return ready;
}
}
}

View file

@ -1,6 +1,7 @@
package com.oitsjustjose.charged_explosives.common.blocks;
import com.oitsjustjose.charged_explosives.ChargedExplosives;
import com.oitsjustjose.charged_explosives.common.TickScheduler;
import com.oitsjustjose.charged_explosives.common.tile.ChargedExplosiveBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@ -16,7 +17,6 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.FaceAttachedHorizontalDirectionalBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
@ -33,6 +33,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nonnull;
import java.util.concurrent.atomic.AtomicInteger;
public class ChargedExplosiveBlock extends FaceAttachedHorizontalDirectionalBlock implements EntityBlock {
@ -105,7 +106,7 @@ public class ChargedExplosiveBlock extends FaceAttachedHorizontalDirectionalBloc
public void onRemove(BlockState oldState, @NotNull Level level, @NotNull BlockPos pos, BlockState newState, boolean moving) {
if (!newState.is(oldState.getBlock())) {
if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity cebe) {
ChargedExplosives.getInstance().proxy.endPreviewExplosion(cebe.getCorners());
ChargedExplosives.getInstance().PROXY.endPreviewExplosion(cebe.getCorners());
}
level.removeBlockEntity(pos);
}
@ -140,21 +141,52 @@ public class ChargedExplosiveBlock extends FaceAttachedHorizontalDirectionalBloc
player.swing(hand);
return InteractionResult.SUCCESS;
}
this.explode(level, pos);
// TODO: configs
final int DELAY_TIME_SECONDS = 5;
final int NUM_WARNING_BEEPS = 5;
ChargedExplosives.getInstance().SCHEDULER.addTask(new TickScheduler.ScheduledTask(() -> this.explode(level, pos), DELAY_TIME_SECONDS));
for (int i = 0; i < NUM_WARNING_BEEPS; i++) {
ChargedExplosives.getInstance().SCHEDULER.addTask(new TickScheduler.ScheduledTask(
() -> level.playSound(null, pos, ChargedExplosives.getInstance().REGISTRY.BeepBoop.get(), SoundSource.BLOCKS, 0.5F, 1.0F),
(DELAY_TIME_SECONDS / NUM_WARNING_BEEPS) * i
));
}
return InteractionResult.CONSUME;
}
private void explode(Level level, BlockPos pos) {
if (level.getBlockEntity(pos) instanceof ChargedExplosiveBlockEntity cebe) {
level.playSound(null, pos, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 1.0F, 1.0F);
ChargedExplosives.getInstance().proxy.endPreviewExplosion(cebe.getCorners());
// ↥ WARNING: the below block will *destroy* cebe, so anything using should go here ↥
cebe.getExplosions().forEach(p -> {
/* ↥ WARNING: the below block will *destroy* cebe, so anything using should go here ↥ */
AtomicInteger explodedCount = new AtomicInteger();
// level.setBlockAndUpdate(p, Blocks.AIR.defaultBlockState());
ChargedExplosives.getInstance().proxy.spawnExplosionParticle(p);
cebe.getExplosions().forEach(p -> {
BlockState state = level.getBlockState(p);
if (!state.hasBlockEntity()) {
/* indestructible blocks will return -1.0F */
if (state.getBlock().defaultDestroyTime() >= 0.0 && !state.isAir()) {
level.removeBlock(p, false);
/* 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);
explodedCount.getAndIncrement();
if (level.getRandom().nextBoolean()) {
ChargedExplosives.getInstance().PROXY.spawnExplosionParticle(p);
}
}
}
});
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

@ -36,7 +36,7 @@ public class ChargedExplosiveItem extends BlockItem {
// Set NBT if it hasn't been already
ItemStack stack = player.getItemInHand(hand);
stack.getOrCreateTag();
ChargedExplosives.getInstance().proxy.openExplosiveGui(player, stack);
ChargedExplosives.getInstance().PROXY.openExplosiveGui(player, stack);
return super.use(level, player, hand);
}

View file

@ -4,6 +4,8 @@ import com.oitsjustjose.charged_explosives.ChargedExplosives;
import com.oitsjustjose.charged_explosives.common.blocks.ChargedExplosiveBlock;
import com.oitsjustjose.charged_explosives.common.items.ChargedExplosiveItem;
import com.oitsjustjose.charged_explosives.common.tile.ChargedExplosiveBlockEntity;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@ -16,8 +18,10 @@ public class Registry {
public final DeferredRegister<Block> BlockRegistry = DeferredRegister.create(ForgeRegistries.BLOCKS, ChargedExplosives.MODID);
public final DeferredRegister<Item> ItemRegistry = DeferredRegister.create(ForgeRegistries.ITEMS, ChargedExplosives.MODID);
public final DeferredRegister<BlockEntityType<?>> BlockEntityTypeRegistry = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, ChargedExplosives.MODID);
public final DeferredRegister<SoundEvent> SoundEventRegistry = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, ChargedExplosives.MODID);
public final RegistryObject<Block> CeBlock = BlockRegistry.register("charged_explosive", ChargedExplosiveBlock::new);
public final RegistryObject<Item> CeItem = ItemRegistry.register("charged_explosive", () -> new ChargedExplosiveItem(CeBlock.get()));
public final RegistryObject<BlockEntityType<ChargedExplosiveBlockEntity>> CeBlockEntityType = BlockEntityTypeRegistry.register("charged_explosive", () -> BlockEntityType.Builder.of(ChargedExplosiveBlockEntity::new, Blocks.AIR).build(null));
public final RegistryObject<SoundEvent> BeepBoop = SoundEventRegistry.register("shapedchargebeep", () -> new SoundEvent(new ResourceLocation(ChargedExplosives.MODID, "shapedchargebeep")));
}

View file

@ -11,7 +11,6 @@ import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.AttachFace;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@ -41,7 +40,7 @@ public class ChargedExplosiveBlockEntity extends BlockEntity {
this.explosionHeight = tag.getInt("explosionHeight");
this.explosionDepth = tag.getInt("explosionDepth");
calculateExplosions();
ChargedExplosives.getInstance().proxy.startPreviewExplosion(this.cornerToCorner);
ChargedExplosives.getInstance().PROXY.startPreviewExplosion(this.cornerToCorner);
this.setChanged();
}
@ -100,10 +99,10 @@ public class ChargedExplosiveBlockEntity extends BlockEntity {
endZ = pos.getZ() + explosionDepth + 1;
}
case SOUTH -> {
startX = pos.getX() - (int) Math.ceil(explosionWidth / 2F) + 1;
endX = pos.getX() + (int) Math.floor(explosionWidth / 2F) + 1;
startY = pos.getY() - (int) Math.ceil(explosionHeight / 2F);
endY = pos.getY() + (int) Math.floor(explosionHeight / 2F);
startX = pos.getX() - (int) Math.floor(explosionWidth / 2F);
endX = pos.getX() + (int) Math.ceil(explosionWidth / 2F);
startY = pos.getY() - (int) Math.floor(explosionHeight / 2F);
endY = pos.getY() + (int) Math.ceil(explosionHeight / 2F);
startZ = pos.getZ() - explosionDepth;
endZ = pos.getZ();
}
@ -116,12 +115,12 @@ public class ChargedExplosiveBlockEntity extends BlockEntity {
endZ = pos.getZ() + (int) Math.ceil(explosionWidth / 2F);
}
case WEST -> {
startX = pos.getX();
endX = pos.getX() + explosionDepth;
startY = pos.getY() - (int) Math.ceil(explosionHeight / 2F);
endY = pos.getY() + (int) Math.floor(explosionHeight / 2F);
startZ = pos.getZ() - (int) Math.ceil(explosionWidth / 2F) + 1;
endZ = pos.getZ() + (int) Math.floor(explosionWidth / 2F) + 1;
startX = pos.getX() + 1;
endX = pos.getX() + explosionDepth + 1;
startY = pos.getY() - (int) Math.floor(explosionHeight / 2F);
endY = pos.getY() + (int) Math.ceil(explosionHeight / 2F);
startZ = pos.getZ() - (int) Math.floor(explosionWidth / 2F);
endZ = pos.getZ() + (int) Math.ceil(explosionWidth / 2F);
}
default -> {
break;

View file

@ -1,55 +1,55 @@
{
"variants": {
"face=ceiling,facing=east": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"x": 180,
"y": 270
},
"face=ceiling,facing=north": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"x": 180,
"y": 180
},
"face=ceiling,facing=south": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"x": 180
},
"face=ceiling,facing=west": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"x": 180,
"y": 90
},
"face=floor,facing=east": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"y": 90
},
"face=floor,facing=north": {
"model": "charged_explosives:item/charged_explosive"
"model": "charged_explosives:block/charged_explosive"
},
"face=floor,facing=south": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"y": 180
},
"face=floor,facing=west": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"y": 270
},
"face=wall,facing=east": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"x": 90,
"y": 90
},
"face=wall,facing=north": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"x": 90
},
"face=wall,facing=south": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"x": 90,
"y": 180
},
"face=wall,facing=west": {
"model": "charged_explosives:item/charged_explosive",
"model": "charged_explosives:block/charged_explosive",
"x": 90,
"y": 270
}

View file

@ -8,5 +8,6 @@
"charged_explosives.depth_tooltip": " §8Depth: §8%s§r",
"charged_explosives.height_tooltip": " §8Height: §8%s§r",
"charged_explosives.needs_init": "This Explosive Needs to be Configured",
"charge.beep.boops": "§cCharged Explosive Beeps Aggressively§r",
"block.charged_explosives.charged_explosive": "Explosive Charge"
}

View file

@ -0,0 +1,80 @@
{
"credit": "Made with Blockbench",
"texture_size": [4, 4],
"textures": {
"0": "charged_explosives:block/charged_explosive_main",
"2": "charged_explosives:block/shaped_charge_light",
"particle": "charged_explosives:block/charged_explosive_main"
},
"elements": [
{
"name": "charged_explosive_main",
"from": [2, 0, 4],
"to": [14, 3, 12],
"faces": {
"north": {"uv": [0, 10, 6, 13], "texture": "#0"},
"east": {"uv": [6, 10, 10, 13], "texture": "#0"},
"south": {"uv": [0, 13, 6, 16], "texture": "#0"},
"west": {"uv": [6, 13, 10, 16], "texture": "#0"},
"up": {"uv": [0, 2, 6, 10], "texture": "#0"},
"down": {"uv": [6, 2, 12, 10], "texture": "#0"}
}
},
{
"name": "shaped_charge_light",
"from": [10, 3, 7],
"to": [12, 4, 9],
"faces": {
"north": {"uv": [8, 0, 16, 4], "texture": "#2"},
"east": {"uv": [8, 8, 16, 12], "texture": "#2"},
"south": {"uv": [8, 8, 16, 4], "texture": "#2"},
"west": {"uv": [8, 12, 16, 16], "texture": "#2"},
"up": {"uv": [0, 0, 8, 8], "texture": "#2"},
"down": {"uv": [0, 8, 8, 16], "texture": "#2"}
}
}
],
"display": {
"thirdperson_righthand": {
"translation": [0, 3, 1],
"scale": [0.55, 0.55, 0.55]
},
"thirdperson_lefthand": {
"rotation": [65, 0, 0],
"translation": [0, 3, 4.75],
"scale": [0.75, 0.75, 0.75]
},
"firstperson_righthand": {
"rotation": [65, 0, 0],
"translation": [0, 3.25, 0]
},
"firstperson_lefthand": {
"rotation": [65, 0, 0],
"translation": [0, 3.25, 0]
},
"ground": {
"translation": [0, 3, 0],
"scale": [0.75, 0.75, 0.75]
},
"gui": {
"rotation": [30, 45, 0],
"translation": [0, 5.25, 0]
},
"head": {
"rotation": [-90, -180, 0],
"translation": [0, 7.25, -14.5]
},
"fixed": {
"rotation": [-90, -180, 0],
"translation": [0, 0, -8]
}
},
"groups": [
{
"name": "shaped charge",
"origin": [0, 0, 0],
"color": 0,
"children": [0, 1]
}
]
}

View file

@ -1,45 +1,3 @@
{
"credit": "Rorax :)",
"texture_size": [4, 4],
"textures": {
"0": "charged_explosives:block/charged_explosive_main",
"1": "charged_explosives:block/shaped_charge_light",
"particle": "charged_explosives:block/charged_explosive_main"
},
"elements": [
{
"name": "charged_explosive_main",
"from": [2, 0, 4],
"to": [14, 3, 12],
"faces": {
"north": {"uv": [0, 10, 6, 13], "texture": "#0"},
"east": {"uv": [6, 10, 10, 13], "texture": "#0"},
"south": {"uv": [0, 13, 6, 16], "texture": "#0"},
"west": {"uv": [6, 13, 10, 16], "texture": "#0"},
"up": {"uv": [0, 2, 6, 10], "texture": "#0"},
"down": {"uv": [6, 2, 12, 10], "texture": "#0"}
}
},
{
"name": "shaped_charge_light",
"from": [10, 3, 7],
"to": [12, 4, 9],
"faces": {
"north": {"uv": [8, 0, 16, 4], "texture": "#1"},
"east": {"uv": [8, 8, 16, 12], "texture": "#1"},
"south": {"uv": [8, 8, 16, 4], "texture": "#1"},
"west": {"uv": [8, 12, 16, 16], "texture": "#1"},
"up": {"uv": [0, 0, 8, 8], "texture": "#1"},
"down": {"uv": [0, 8, 8, 16], "texture": "#1"}
}
}
],
"groups": [
{
"name": "shaped charge",
"origin": [0, 0, 0],
"color": 0,
"children": [0, 1]
}
]
"parent": "charged_explosives:block/charged_explosive"
}

View file

@ -0,0 +1,6 @@
{
"shapedchargebeep": {
"subtitle": "charge.beep.boops",
"sounds": ["charged_explosives:shapedchargebeep"]
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 B

After

Width:  |  Height:  |  Size: 137 B

Before After
Before After

View file

@ -0,0 +1,6 @@
{
"animation": {
"interpolate": false,
"frametime": 5
}
}