From 7b18c658b7c2696b51a632b511e9fa63296ef2f1 Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Sun, 27 Jun 2021 23:15:51 -0700 Subject: [PATCH] Polished bells - Fix cursed bells not rendering on contraptions - Prevent players in spectator from creating soul pulses - Improve and format some bell-related code --- .../java/com/simibubi/create/AllBlocks.java | 16 +---- .../actors/BellMovementBehaviour.java | 2 +- .../curiosities/bell/AbstractBellBlock.java | 7 ++- .../bell/AbstractBellTileEntity.java | 2 +- .../curiosities/bell}/BasicParticleData.java | 5 +- .../curiosities/bell/BellRenderer.java | 6 +- .../bell/CursedBellItemPulser.java | 42 ------------- .../bell/CursedBellMovementBehaviour.java | 7 +-- .../curiosities/bell/CursedBellPulser.java | 42 +++++++++++++ .../bell/CursedBellTileEntity.java | 19 ++++-- .../bell/CustomRotationParticle.java | 37 +++++++----- .../curiosities/bell/PeculiarBellBlock.java | 17 +++--- .../bell/PeculiarBellTileEntity.java | 2 +- .../curiosities/bell/SoulBaseParticle.java | 6 +- .../curiosities/bell/SoulParticle.java | 1 - .../curiosities/bell/SoulPulseEffect.java | 13 ++-- .../bell/SoulPulseEffectHandler.java | 60 ++----------------- .../bell/SoulPulseEffectPacket.java | 45 ++++++++++++++ .../create/foundation/data/BlockStateGen.java | 7 --- .../foundation/data/BuilderTransformers.java | 14 +++++ .../foundation/networking/AllPackets.java | 4 +- .../block/cursed_bell/block_ceiling.json | 2 +- .../models/block/cursed_bell/block_floor.json | 2 +- .../create/models/block/cursed_bell/item.json | 2 +- 24 files changed, 183 insertions(+), 177 deletions(-) rename src/main/java/com/simibubi/create/{foundation/data => content/curiosities/bell}/BasicParticleData.java (91%) delete mode 100644 src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellItemPulser.java create mode 100644 src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellPulser.java create mode 100644 src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffectPacket.java diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 6cc651e20..a0a410712 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -1306,26 +1306,14 @@ public class AllBlocks { public static final BlockEntry PECULIAR_BELL = REGISTRATE.block("peculiar_bell", PeculiarBellBlock::new) - .initialProperties(SharedProperties::softMetal) - .properties(p -> p.nonOpaque() - .sound(SoundType.ANVIL)) - .addLayer(() -> RenderType::getCutoutMipped) - .tag(AllBlockTags.BRITTLE.tag) + .transform(BuilderTransformers.bell()) .onRegister(addMovementBehaviour(new BellMovementBehaviour())) - .blockstate(BlockStateGen.bell()) - .item() - .transform(customItemModel()) .register(); public static final BlockEntry CURSED_BELL = REGISTRATE.block("cursed_bell", CursedBellBlock::new) - .initialProperties(() -> PECULIAR_BELL.get()) - .addLayer(() -> RenderType::getCutoutMipped) - .tag(AllBlockTags.BRITTLE.tag) + .transform(BuilderTransformers.bell()) .onRegister(addMovementBehaviour(new CursedBellMovementBehaviour())) - .blockstate(BlockStateGen.bell()) - .item() - .transform(customItemModel()) .register(); // Materials diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java index ad8ae6504..10ab639cd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java @@ -38,7 +38,7 @@ public class BellMovementBehaviour extends MovementBehaviour { Block block = context.state.getBlock(); if (block instanceof AbstractBellBlock) { - ((AbstractBellBlock) block).playSound(world, pos); + ((AbstractBellBlock) block).playSound(world, pos); } else { // Vanilla bell sound world.playSound(null, pos, SoundEvents.BLOCK_BELL_USE, diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellBlock.java b/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellBlock.java index 8897b5ce3..36d98baa4 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellBlock.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellBlock.java @@ -52,7 +52,7 @@ public abstract class AbstractBellBlock exten if (direction == null) direction = world.getBlockState(pos).get(field_220133_a); - if (!this.canRingFrom(state, direction, hit.getHitVec().y - (double)pos.getY())) + if (!this.canRingFrom(state, direction, hit.getHitVec().y - pos.getY())) return false; TE te = getTileEntity(world, pos); @@ -64,6 +64,7 @@ public abstract class AbstractBellBlock exten if (player != null) player.addStat(Stats.BELL_RING); } + return true; } @@ -74,8 +75,8 @@ public abstract class AbstractBellBlock exten return false; Direction direction = state.get(field_220133_a); - BellAttachment bellattachment = state.get(field_220134_b); - switch(bellattachment) { + BellAttachment bellAttachment = state.get(field_220134_b); + switch(bellAttachment) { case FLOOR: case CEILING: return direction.getAxis() == hitDir.getAxis(); diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellTileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellTileEntity.java index 86403ece5..0957d7f19 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellTileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellTileEntity.java @@ -47,6 +47,6 @@ public abstract class AbstractBellTileEntity extends SmartTileEntity { } } - public abstract PartialModel getBellPartial(); + public abstract PartialModel getBellModel(); } diff --git a/src/main/java/com/simibubi/create/foundation/data/BasicParticleData.java b/src/main/java/com/simibubi/create/content/curiosities/bell/BasicParticleData.java similarity index 91% rename from src/main/java/com/simibubi/create/foundation/data/BasicParticleData.java rename to src/main/java/com/simibubi/create/content/curiosities/bell/BasicParticleData.java index 4671f8c5d..9f6374e97 100644 --- a/src/main/java/com/simibubi/create/foundation/data/BasicParticleData.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/BasicParticleData.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.data; +package com.simibubi.create.content.curiosities.bell; import javax.annotation.ParametersAreNonnullByDefault; @@ -20,7 +20,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault -public abstract class BasicParticleData implements IParticleData, ICustomParticleDataWithSprite> { +public abstract class BasicParticleData implements IParticleData, ICustomParticleDataWithSprite> { public BasicParticleData() { } @@ -32,6 +32,7 @@ public abstract class BasicParticleData implements IParticl public BasicParticleData deserialize(ParticleType> arg0, StringReader reader) { return data; } + @Override public BasicParticleData read(ParticleType> type, PacketBuffer buffer) { return data; diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/BellRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/bell/BellRenderer.java index 558444652..1b68c75a4 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/BellRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/BellRenderer.java @@ -29,7 +29,7 @@ public class BellRenderer extends SafeTileEnt Direction facing = state.get(BellBlock.field_220133_a); BellAttachment attachment = state.get(BellBlock.field_220134_b); - SuperByteBuffer bell = PartialBufferer.get(te.getBellPartial(), state); + SuperByteBuffer bell = PartialBufferer.get(te.getBellModel(), state); if (te.isRinging) bell.rotateCentered(te.ringDirection.rotateYCCW(), getSwingAngle(te.ringingTicks + partialTicks)); @@ -37,7 +37,7 @@ public class BellRenderer extends SafeTileEnt float rY = AngleHelper.horizontalAngle(facing); if (attachment == BellAttachment.SINGLE_WALL || attachment == BellAttachment.DOUBLE_WALL) rY += 90; - bell.rotateCentered(Direction.UP, (float) (rY / 180 * Math.PI)); + bell.rotateCentered(Direction.UP, AngleHelper.rad(rY)); IVertexBuilder vb = buffer.getBuffer(RenderType.getCutout()); int lightCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), state, te.getPos()); @@ -46,7 +46,7 @@ public class BellRenderer extends SafeTileEnt public static float getSwingAngle(float time) { float t = time / 1.5f; - return 1.2f * MathHelper.sin(t / (float)Math.PI) / (2.5f + t / 3.0f); + return 1.2f * MathHelper.sin(t / (float) Math.PI) / (2.5f + t / 3.0f); } } diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellItemPulser.java b/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellItemPulser.java deleted file mode 100644 index 88e5d743f..000000000 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellItemPulser.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.simibubi.create.content.curiosities.bell; - -import com.simibubi.create.AllBlocks; - -import net.minecraft.block.Block; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.util.Hand; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.LogicalSide; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; - -@EventBusSubscriber -public class CursedBellItemPulser { - - public static final int DISTANCE = 2; - public static final int RECHARGE_TICKS = 8; - - @SubscribeEvent - public static void bellItemCreatesPulses(TickEvent.PlayerTickEvent event) { - if (event.phase != TickEvent.Phase.END) - return; - if (event.side != LogicalSide.SERVER) - return; - - if (event.player.world.getGameTime() % RECHARGE_TICKS != 0) - return; - - for (Hand hand : Hand.values()) { - Item held = event.player.getHeldItem(hand).getItem(); - if (!(held instanceof BlockItem)) - continue; - Block block = ((BlockItem) held).getBlock(); - if (!block.is(AllBlocks.CURSED_BELL.get())) - continue; - - SoulPulseEffectHandler.sendPulsePacket(event.player.world, event.player.getBlockPos(), DISTANCE, false); - } - } - -} diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellMovementBehaviour.java b/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellMovementBehaviour.java index 9e7fa722e..7976cf8a1 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellMovementBehaviour.java @@ -1,12 +1,11 @@ package com.simibubi.create.content.curiosities.bell; import com.simibubi.create.content.contraptions.components.actors.BellMovementBehaviour; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import net.minecraft.util.math.BlockPos; -public class CursedBellMovementBehaviour extends MovementBehaviour { +public class CursedBellMovementBehaviour extends BellMovementBehaviour { public static final int DISTANCE = 3; @@ -20,9 +19,9 @@ public class CursedBellMovementBehaviour extends MovementBehaviour { @Override public void visitNewPosition(MovementContext context, BlockPos pos) { if (!context.world.isRemote && getRecharge(context) == 0) { - SoulPulseEffectHandler.sendPulsePacket(context.world, pos, DISTANCE, true); + CursedBellPulser.sendPulse(context.world, pos, DISTANCE, true); setRecharge(context, CursedBellTileEntity.RECHARGE_TICKS); - BellMovementBehaviour.playSound(context); + playSound(context); } } diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellPulser.java b/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellPulser.java new file mode 100644 index 000000000..8157058d2 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellPulser.java @@ -0,0 +1,42 @@ +package com.simibubi.create.content.curiosities.bell; + +import com.simibubi.create.AllBlocks; +import com.simibubi.create.foundation.networking.AllPackets; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.LogicalSide; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.network.PacketDistributor; + +@EventBusSubscriber +public class CursedBellPulser { + + public static final int DISTANCE = 2; + public static final int RECHARGE_TICKS = 8; + + @SubscribeEvent + public static void cursedBellCreatesPulse(TickEvent.PlayerTickEvent event) { + if (event.phase != TickEvent.Phase.END) + return; + if (event.side != LogicalSide.SERVER) + return; + if (event.player.isSpectator()) + return; + + if (event.player.world.getGameTime() % RECHARGE_TICKS != 0) + return; + + if (event.player.isHolding(AllBlocks.CURSED_BELL::is)) + sendPulse(event.player.world, event.player.getBlockPos(), DISTANCE, false); + } + + public static void sendPulse(World world, BlockPos pos, int distance, boolean canOverlap) { + Chunk chunk = world.getChunkAt(pos); + AllPackets.channel.send(PacketDistributor.TRACKING_CHUNK.with(() -> chunk), new SoulPulseEffectPacket(pos, distance, canOverlap)); + } + +} diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellTileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellTileEntity.java index 7bfe6ba71..d9757a693 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellTileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/CursedBellTileEntity.java @@ -33,7 +33,7 @@ public class CursedBellTileEntity extends AbstractBellTileEntity { public void addBehaviours(List behaviours) { } @Override - public PartialModel getBellPartial() { + public PartialModel getBellModel() { return AllBlockPartials.CURSED_BELL; } @@ -46,7 +46,7 @@ public class CursedBellTileEntity extends AbstractBellTileEntity { return false; if (!world.isRemote) - SoulPulseEffectHandler.sendPulsePacket(world, pos, DISTANCE, true); + CursedBellPulser.sendPulse(world, pos, DISTANCE, true); startEffect(); @@ -82,17 +82,24 @@ public class CursedBellTileEntity extends AbstractBellTileEntity { return; Random rand = world.getRandom(); - if (rand.nextFloat() > 1/4f) + if (rand.nextFloat() > 0.25f) return; + spawnParticle(rand); + playSound(rand); + } + + protected void spawnParticle(Random rand) { double x = pos.getX() + rand.nextDouble(); double y = pos.getY() + 0.5; double z = pos.getZ() + rand.nextDouble(); - double vx = rand.nextDouble()*0.04 - 0.02; + double vx = rand.nextDouble() * 0.04 - 0.02; double vy = 0.1; - double vz = rand.nextDouble()*0.04 - 0.02; - this.world.addParticle(ParticleTypes.SOUL, x, y, z, vx, vy, vz); + double vz = rand.nextDouble() * 0.04 - 0.02; + world.addParticle(ParticleTypes.SOUL, x, y, z, vx, vy, vz); + } + protected void playSound(Random rand) { float vol = rand.nextFloat() * 0.4F + rand.nextFloat() > 0.9F ? 0.6F : 0.0F; float pitch = 0.6F + rand.nextFloat() * 0.4F; world.playSound(null, pos, SoundEvents.PARTICLE_SOUL_ESCAPE, SoundCategory.BLOCKS, vol, pitch); diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/CustomRotationParticle.java b/src/main/java/com/simibubi/create/content/curiosities/bell/CustomRotationParticle.java index 241c23611..3e82e828d 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/CustomRotationParticle.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/CustomRotationParticle.java @@ -27,8 +27,8 @@ public class CustomRotationParticle extends SimpleAnimatedParticle { public Quaternion getCustomRotation(ActiveRenderInfo camera, float partialTicks) { Quaternion quaternion = new Quaternion(camera.getRotation()); - if (this.particleAngle != 0.0F) { - float angle = MathHelper.lerp(partialTicks, this.prevParticleAngle, this.particleAngle); + if (particleAngle != 0.0F) { + float angle = MathHelper.lerp(partialTicks, prevParticleAngle, particleAngle); quaternion.multiply(Vector3f.POSITIVE_Z.getRadialQuaternion(angle)); } return quaternion; @@ -37,12 +37,17 @@ public class CustomRotationParticle extends SimpleAnimatedParticle { @Override public void buildGeometry(IVertexBuilder builder, ActiveRenderInfo camera, float partialTicks) { Vector3d cameraPos = camera.getProjectedView(); - float originX = (float)(MathHelper.lerp(partialTicks, this.prevPosX, this.posX) - cameraPos.getX()); - float originY = (float)(MathHelper.lerp(partialTicks, this.prevPosY, this.posY) - cameraPos.getY()); - float originZ = (float)(MathHelper.lerp(partialTicks, this.prevPosZ, this.posZ) - cameraPos.getZ()); + float originX = (float) (MathHelper.lerp(partialTicks, prevPosX, posX) - cameraPos.getX()); + float originY = (float) (MathHelper.lerp(partialTicks, prevPosY, posY) - cameraPos.getY()); + float originZ = (float) (MathHelper.lerp(partialTicks, prevPosZ, posZ) - cameraPos.getZ()); - Vector3f[] vertices = new Vector3f[]{new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F)}; - float scale = this.getScale(partialTicks); + Vector3f[] vertices = new Vector3f[] { + new Vector3f(-1.0F, -1.0F, 0.0F), + new Vector3f(-1.0F, 1.0F, 0.0F), + new Vector3f(1.0F, 1.0F, 0.0F), + new Vector3f(1.0F, -1.0F, 0.0F) + }; + float scale = getScale(partialTicks); Quaternion rotation = getCustomRotation(camera, partialTicks); for(int i = 0; i < 4; ++i) { @@ -52,14 +57,14 @@ public class CustomRotationParticle extends SimpleAnimatedParticle { vertex.add(originX, originY, originZ); } - float minU = mirror ? this.getMaxU() : this.getMinU(); - float maxU = mirror ? this.getMinU() : this.getMaxU(); - float minV = this.getMinV(); - float maxV = this.getMaxV(); - int brightness = this.getBrightnessForRender(partialTicks); - builder.vertex(vertices[0].getX(), vertices[0].getY(), vertices[0].getZ()).texture(maxU, maxV).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).light(brightness).endVertex(); - builder.vertex(vertices[1].getX(), vertices[1].getY(), vertices[1].getZ()).texture(maxU, minV).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).light(brightness).endVertex(); - builder.vertex(vertices[2].getX(), vertices[2].getY(), vertices[2].getZ()).texture(minU, minV).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).light(brightness).endVertex(); - builder.vertex(vertices[3].getX(), vertices[3].getY(), vertices[3].getZ()).texture(minU, maxV).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).light(brightness).endVertex(); + float minU = mirror ? getMaxU() : getMinU(); + float maxU = mirror ? getMinU() : getMaxU(); + float minV = getMinV(); + float maxV = getMaxV(); + int brightness = getBrightnessForRender(partialTicks); + builder.vertex(vertices[0].getX(), vertices[0].getY(), vertices[0].getZ()).texture(maxU, maxV).color(particleRed, particleGreen, particleBlue, particleAlpha).light(brightness).endVertex(); + builder.vertex(vertices[1].getX(), vertices[1].getY(), vertices[1].getZ()).texture(maxU, minV).color(particleRed, particleGreen, particleBlue, particleAlpha).light(brightness).endVertex(); + builder.vertex(vertices[2].getX(), vertices[2].getY(), vertices[2].getZ()).texture(minU, minV).color(particleRed, particleGreen, particleBlue, particleAlpha).light(brightness).endVertex(); + builder.vertex(vertices[3].getX(), vertices[3].getY(), vertices[3].getZ()).texture(minU, maxV).color(particleRed, particleGreen, particleBlue, particleAlpha).light(brightness).endVertex(); } } diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/PeculiarBellBlock.java b/src/main/java/com/simibubi/create/content/curiosities/bell/PeculiarBellBlock.java index cc674a82e..ae11068e0 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/PeculiarBellBlock.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/PeculiarBellBlock.java @@ -6,7 +6,6 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.AllTileEntities; -import net.minecraft.block.BellBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -32,7 +31,9 @@ public class PeculiarBellBlock extends AbstractBellBlock } @Override - public Class getTileEntityClass() { return PeculiarBellTileEntity.class; } + public Class getTileEntityClass() { + return PeculiarBellTileEntity.class; + } @Override public void playSound(World world, BlockPos pos) { @@ -72,18 +73,18 @@ public class PeculiarBellBlock extends AbstractBellBlock } return AllBlocks.CURSED_BELL.getDefaultState() - .with(BellBlock.field_220133_a, state.get(BellBlock.field_220133_a)) - .with(BellBlock.field_220134_b, state.get(BellBlock.field_220134_b)) - .with(BellBlock.POWERED, state.get(BellBlock.POWERED)); + .with(CursedBellBlock.field_220133_a, state.get(field_220133_a)) + .with(CursedBellBlock.field_220134_b, state.get(field_220134_b)) + .with(CursedBellBlock.POWERED, state.get(POWERED)); } public void spawnConversionParticles(IWorld world, BlockPos blockPos) { Random random = world.getRandom(); int num = random.nextInt(10) + 15; for (int i = 0; i < num; i++) { - float pitch = random.nextFloat()*120 - 90; - float yaw = random.nextFloat()*360; - Vector3d vel = Vector3d.fromPitchYaw(pitch, yaw).scale(random.nextDouble()*0.1 + 0.1); + float pitch = random.nextFloat() * 120 - 90; + float yaw = random.nextFloat() * 360; + Vector3d vel = Vector3d.fromPitchYaw(pitch, yaw).scale(random.nextDouble() * 0.1 + 0.1); Vector3d pos = Vector3d.ofCenter(blockPos); world.addParticle(ParticleTypes.SOUL_FIRE_FLAME, pos.x, pos.y, pos.z, vel.x, vel.y, vel.z); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/PeculiarBellTileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/bell/PeculiarBellTileEntity.java index 065519374..e58434e49 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/PeculiarBellTileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/PeculiarBellTileEntity.java @@ -12,7 +12,7 @@ public class PeculiarBellTileEntity extends AbstractBellTileEntity { } @Override - public PartialModel getBellPartial() { + public PartialModel getBellModel() { return AllBlockPartials.PECULIAR_BELL; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/SoulBaseParticle.java b/src/main/java/com/simibubi/create/content/curiosities/bell/SoulBaseParticle.java index 7f8f26b4c..ce3f4820f 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/SoulBaseParticle.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/SoulBaseParticle.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.curiosities.bell; import com.simibubi.create.AllParticleTypes; -import com.simibubi.create.foundation.data.BasicParticleData; import net.minecraft.client.particle.IAnimatedSprite; import net.minecraft.client.renderer.ActiveRenderInfo; @@ -19,9 +18,9 @@ public class SoulBaseParticle extends CustomRotationParticle { super(worldIn, x, y, z, spriteSet, 0); this.animatedSprite = spriteSet; this.particleScale = 0.5f; - this.setSize(this.particleScale,this.particleScale); + this.setSize(this.particleScale, this.particleScale); this.loopLength = 16 + (int) (this.rand.nextFloat() * 2f - 1f); - this.maxAge = (int)(90.0F / (this.rand.nextFloat() * 0.36F + 0.64F)); + this.maxAge = (int) (90.0F / (this.rand.nextFloat() * 0.36F + 0.64F)); this.selectSpriteLoopingWithAge(animatedSprite); this.field_21507 = true; // disable movement } @@ -45,6 +44,7 @@ public class SoulBaseParticle extends CustomRotationParticle { public IBasicParticleFactory getBasicFactory() { return SoulBaseParticle::new; } + @Override public ParticleType getType() { return AllParticleTypes.SOUL_BASE.get(); diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/SoulParticle.java b/src/main/java/com/simibubi/create/content/curiosities/bell/SoulParticle.java index 25212b2d1..0a439b0dd 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/SoulParticle.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/SoulParticle.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.curiosities.bell; import com.simibubi.create.AllParticleTypes; -import com.simibubi.create.foundation.data.BasicParticleData; import net.minecraft.client.particle.IAnimatedSprite; import net.minecraft.client.renderer.ActiveRenderInfo; diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffect.java b/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffect.java index 6f076222c..b78931611 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffect.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffect.java @@ -38,7 +38,9 @@ public class SoulPulseEffect { return ticks <= -WAITING_TICKS; } - public boolean canOverlap() { return added == null; } + public boolean canOverlap() { + return added == null; + } public List tick(World world) { if (finished()) @@ -69,7 +71,7 @@ public class SoulPulseEffect { .collect(Collectors.toList()); } - public static boolean canSpawnSoulAt(World world, BlockPos at) { + public boolean canSpawnSoulAt(World world, BlockPos at) { EntityType dummy = EntityType.ZOMBIE; double dummyWidth = 0.2, dummyHeight = 0.75; double w2 = dummyWidth / 2; @@ -84,7 +86,7 @@ public class SoulPulseEffect { ), (a,b) -> true).allMatch(VoxelShape::isEmpty); } - public static void spawnParticles(World world, BlockPos at) { + public void spawnParticles(World world, BlockPos at) { if (world == null || !world.isRemote) return; @@ -101,10 +103,9 @@ public class SoulPulseEffect { for (int x = 0; x < MAX_DISTANCE; x++) { for (int y = 0; y < MAX_DISTANCE; y++) { for (int z = 0; z < MAX_DISTANCE; z++) { - BlockPos candidate = new BlockPos(x,y,z); + BlockPos candidate = new BlockPos(x, y, z); - int dist = (int) Math.round(Math.sqrt( - candidate.distanceSq(0,0,0,false))); + int dist = (int) Math.round(Math.sqrt(candidate.distanceSq(0, 0, 0, false))); if (dist > MAX_DISTANCE) continue; if (dist <= 0) diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffectHandler.java b/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffectHandler.java index feb43836f..c52d112bd 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffectHandler.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffectHandler.java @@ -4,18 +4,9 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.function.Supplier; -import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.networking.AllPackets; -import com.simibubi.create.foundation.networking.SimplePacketBase; - -import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; -import net.minecraftforge.fml.network.NetworkEvent; -import net.minecraftforge.fml.network.PacketDistributor; public class SoulPulseEffectHandler { @@ -35,14 +26,14 @@ public class SoulPulseEffectHandler { if (pulse.canOverlap()) { for (BlockPos pos : spawns) { - SoulPulseEffect.spawnParticles(world, pos); + pulse.spawnParticles(world, pos); } } else { for (BlockPos pos : spawns) { if (occupied.contains(pos)) continue; - SoulPulseEffect.spawnParticles(world, pos); + pulse.spawnParticles(world, pos); pulse.added.add(pos); occupied.add(pos); } @@ -56,52 +47,13 @@ public class SoulPulseEffectHandler { pulses.removeIf(SoulPulseEffect::finished); } + public void addPulse(SoulPulseEffect pulse) { + pulses.add(pulse); + } + public void refresh() { pulses.clear(); occupied.clear(); } - public static void sendPulsePacket(World world, BlockPos at, int distance, boolean canOverlap) { - Chunk chunk = world.getChunkAt(at); - AllPackets.channel.send(PacketDistributor.TRACKING_CHUNK.with(() -> chunk), new Packet(at, distance, canOverlap)); - } - - private void handlePulse(BlockPos pos, int distance, boolean overlaps) { - pulses.add(new SoulPulseEffect(pos, distance, overlaps)); - } - - - public static class Packet extends SimplePacketBase { - public BlockPos pos; - public int distance; - public boolean overlaps; - - public Packet(BlockPos pos, int distance, boolean overlaps) { - this.pos = pos; - this.distance = distance; - this.overlaps = overlaps; - } - - public Packet(PacketBuffer buffer) { - pos = new BlockPos(buffer.readInt(), buffer.readInt(), buffer.readInt()); - distance = buffer.readInt(); - overlaps = buffer.readBoolean(); - } - - @Override - public void write(PacketBuffer buffer) { - buffer.writeInt(pos.getX()); - buffer.writeInt(pos.getY()); - buffer.writeInt(pos.getZ()); - buffer.writeInt(distance); - buffer.writeBoolean(overlaps); - } - - @Override - public void handle(Supplier context) { - context.get().enqueueWork(() -> CreateClient.SOUL_PULSE_EFFECT_HANDLER.handlePulse(pos, distance, overlaps)); - context.get().setPacketHandled(true); - } - } - } diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffectPacket.java b/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffectPacket.java new file mode 100644 index 000000000..939c4aaf4 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/SoulPulseEffectPacket.java @@ -0,0 +1,45 @@ +package com.simibubi.create.content.curiosities.bell; + +import java.util.function.Supplier; + +import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.networking.SimplePacketBase; + +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.network.NetworkEvent; + +public class SoulPulseEffectPacket extends SimplePacketBase { + + public BlockPos pos; + public int distance; + public boolean canOverlap; + + public SoulPulseEffectPacket(BlockPos pos, int distance, boolean overlaps) { + this.pos = pos; + this.distance = distance; + this.canOverlap = overlaps; + } + + public SoulPulseEffectPacket(PacketBuffer buffer) { + pos = buffer.readBlockPos(); + distance = buffer.readInt(); + canOverlap = buffer.readBoolean(); + } + + @Override + public void write(PacketBuffer buffer) { + buffer.writeBlockPos(pos); + buffer.writeInt(distance); + buffer.writeBoolean(canOverlap); + } + + @Override + public void handle(Supplier context) { + context.get().enqueueWork(() -> { + CreateClient.SOUL_PULSE_EFFECT_HANDLER.addPulse(new SoulPulseEffect(pos, distance, canOverlap)); + }); + context.get().setPacketHandled(true); + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/data/BlockStateGen.java b/src/main/java/com/simibubi/create/foundation/data/BlockStateGen.java index dac5680af..5661543b3 100644 --- a/src/main/java/com/simibubi/create/foundation/data/BlockStateGen.java +++ b/src/main/java/com/simibubi/create/foundation/data/BlockStateGen.java @@ -32,7 +32,6 @@ import com.tterrag.registrate.providers.RegistrateBlockstateProvider; import com.tterrag.registrate.util.nullness.NonNullBiConsumer; import com.tterrag.registrate.util.nullness.NonNullUnaryOperator; -import net.minecraft.block.BellBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.state.BooleanProperty; @@ -463,12 +462,6 @@ public class BlockStateGen { }; } - public static NonNullBiConsumer, RegistrateBlockstateProvider> bell() { - return (c, p) -> p.horizontalBlock(c.getEntry(), state -> - AssetLookup.partialBaseModel(c, p, state.get(BlockStateProperties.BELL_ATTACHMENT).getString()) - ); - } - private static void putPart(Map, ModelFile> coreModels, MultiPartBlockStateBuilder builder, Axis axis, String s, boolean up, boolean down, boolean left, boolean right) { Direction positiveAxis = Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis); diff --git a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java index 5a110f8b7..b8976bad1 100644 --- a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java +++ b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java @@ -29,9 +29,11 @@ import com.tterrag.registrate.builders.BlockBuilder; import com.tterrag.registrate.util.nullness.NonNullUnaryOperator; import net.minecraft.block.Block; +import net.minecraft.block.SoundType; import net.minecraft.client.renderer.RenderType; import net.minecraft.item.DyeColor; import net.minecraft.item.Rarity; +import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.PistonType; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; @@ -216,4 +218,16 @@ public class BuilderTransformers { .transform(ModelGen.customItemModel("crate", type, "single")); } + public static NonNullUnaryOperator> bell() { + return b -> b.initialProperties(SharedProperties::softMetal) + .properties(p -> p.nonOpaque() + .sound(SoundType.ANVIL)) + .addLayer(() -> RenderType::getCutoutMipped) + .tag(AllBlockTags.BRITTLE.tag) + .blockstate((c, p) -> p.horizontalBlock(c.getEntry(), state -> + AssetLookup.partialBaseModel(c, p, state.get(BlockStateProperties.BELL_ATTACHMENT).getString()))) + .item() + .transform(ModelGen.customItemModel()); + } + } diff --git a/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java b/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java index 43f96b197..12c6842a7 100644 --- a/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java +++ b/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java @@ -21,7 +21,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.tra import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartControllerUpdatePacket; import com.simibubi.create.content.contraptions.fluids.actors.FluidSplashPacket; import com.simibubi.create.content.contraptions.relays.advanced.sequencer.ConfigureSequencedGearshiftPacket; -import com.simibubi.create.content.curiosities.bell.SoulPulseEffectHandler; +import com.simibubi.create.content.curiosities.bell.SoulPulseEffectPacket; import com.simibubi.create.content.curiosities.projector.ConfigureProjectorPacket; import com.simibubi.create.content.curiosities.symmetry.SymmetryEffectPacket; import com.simibubi.create.content.curiosities.tools.BlueprintAssignCompleteRecipePacket; @@ -115,7 +115,7 @@ public enum AllPackets { TUNNEL_FLAP(TunnelFlapPacket.class, TunnelFlapPacket::new, PLAY_TO_CLIENT), FUNNEL_FLAP(FunnelFlapPacket.class, FunnelFlapPacket::new, PLAY_TO_CLIENT), POTATO_CANNON(PotatoCannonPacket.class, PotatoCannonPacket::new, PLAY_TO_CLIENT), - SOUL_PULSE(SoulPulseEffectHandler.Packet.class, SoulPulseEffectHandler.Packet::new, PLAY_TO_CLIENT), + SOUL_PULSE(SoulPulseEffectPacket.class, SoulPulseEffectPacket::new, PLAY_TO_CLIENT), PERSISTENT_DATA(ISyncPersistentData.Packet.class, ISyncPersistentData.Packet::new, PLAY_TO_CLIENT), ; diff --git a/src/main/resources/assets/create/models/block/cursed_bell/block_ceiling.json b/src/main/resources/assets/create/models/block/cursed_bell/block_ceiling.json index 2616af7a7..67da4ac5d 100644 --- a/src/main/resources/assets/create/models/block/cursed_bell/block_ceiling.json +++ b/src/main/resources/assets/create/models/block/cursed_bell/block_ceiling.json @@ -3,7 +3,7 @@ "textures": { "1": "create:block/bell_frame_side", "2": "create:block/bell_frame", - "particle": "create:block/bell" + "particle": "create:block/bell" }, "elements": [ { diff --git a/src/main/resources/assets/create/models/block/cursed_bell/block_floor.json b/src/main/resources/assets/create/models/block/cursed_bell/block_floor.json index 6738c29b4..396f9e4e7 100644 --- a/src/main/resources/assets/create/models/block/cursed_bell/block_floor.json +++ b/src/main/resources/assets/create/models/block/cursed_bell/block_floor.json @@ -3,7 +3,7 @@ "textures": { "1": "create:block/bell_frame_side", "2": "create:block/bell_frame", - "particle": "create:block/bell" + "particle": "create:block/bell" }, "elements": [ { diff --git a/src/main/resources/assets/create/models/block/cursed_bell/item.json b/src/main/resources/assets/create/models/block/cursed_bell/item.json index 9a589a6b2..2c1c2327c 100644 --- a/src/main/resources/assets/create/models/block/cursed_bell/item.json +++ b/src/main/resources/assets/create/models/block/cursed_bell/item.json @@ -1,6 +1,6 @@ { "credit": "Made with Blockbench", - "parent": "block/block", + "parent": "block/block", "textures": { "0": "create:block/bell_anim", "particle": "create:block/bell"