Skip to content

Commit 9592fb9

Browse files
committed
various fixes
1 parent f325471 commit 9592fb9

File tree

13 files changed

+177
-31
lines changed

13 files changed

+177
-31
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package galena.oreganized.client.particle;
2+
3+
import net.minecraft.client.multiplayer.ClientLevel;
4+
import net.minecraft.client.particle.Particle;
5+
import net.minecraft.client.particle.ParticleProvider;
6+
import net.minecraft.client.particle.ParticleRenderType;
7+
import net.minecraft.client.particle.SpriteSet;
8+
import net.minecraft.client.particle.TextureSheetParticle;
9+
import net.minecraft.core.particles.SimpleParticleType;
10+
11+
public class BoneFragmentParticle extends TextureSheetParticle {
12+
13+
protected BoneFragmentParticle(ClientLevel level, double x, double y, double z, double xd, double yd, double zd) {
14+
super(level, x, y, z);
15+
this.gravity = 0.04F;
16+
this.xd = xd;
17+
this.yd = yd;
18+
this.zd = zd;
19+
}
20+
21+
@Override
22+
public ParticleRenderType getRenderType() {
23+
return ParticleRenderType.PARTICLE_SHEET_OPAQUE;
24+
}
25+
26+
@Override
27+
public void tick() {
28+
xo = x;
29+
yo = y;
30+
zo = z;
31+
if (lifetime-- <= 0) {
32+
remove();
33+
} else {
34+
yd -= gravity;
35+
move(xd, yd, zd);
36+
xd *= 0.9800000190734863;
37+
yd *= 0.9800000190734863;
38+
zd *= 0.9800000190734863;
39+
}
40+
}
41+
42+
public static class Provider implements ParticleProvider<SimpleParticleType> {
43+
private final SpriteSet sprite;
44+
45+
public Provider(SpriteSet sprites) {
46+
sprite = sprites;
47+
}
48+
49+
@Override
50+
public Particle createParticle(SimpleParticleType type, ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
51+
var particle = new BoneFragmentParticle(level, x, y, z, xSpeed, ySpeed, zSpeed);
52+
particle.setLifetime(level.random.nextInt(20, 20 * 4));
53+
particle.pickSprite(sprite);
54+
return particle;
55+
}
56+
}
57+
58+
}

src/main/java/galena/oreganized/content/block/BonePileBlock.java

+34-7
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,64 @@
99
import net.minecraft.world.entity.Entity;
1010
import net.minecraft.world.entity.LivingEntity;
1111
import net.minecraft.world.entity.item.FallingBlockEntity;
12+
import net.minecraft.world.level.BlockGetter;
1213
import net.minecraft.world.level.Level;
14+
import net.minecraft.world.level.block.Block;
1315
import net.minecraft.world.level.block.FallingBlock;
1416
import net.minecraft.world.level.block.state.BlockState;
1517
import net.minecraft.world.phys.Vec3;
18+
import net.minecraft.world.phys.shapes.CollisionContext;
19+
import net.minecraft.world.phys.shapes.EntityCollisionContext;
20+
import net.minecraft.world.phys.shapes.Shapes;
21+
import net.minecraft.world.phys.shapes.VoxelShape;
1622
import net.minecraftforge.client.extensions.common.IClientBlockExtensions;
1723

1824
import java.util.function.Consumer;
1925

2026
public class BonePileBlock extends FallingBlock {
2127

28+
protected static final VoxelShape SHAPE = Block.box(0.0, 0.0, 0.0, 16.0, 13.0, 16.0);
29+
30+
private static StatePredicate ALWAYS = (s, l, p) -> true;
31+
2232
public BonePileBlock(Properties properties) {
23-
super(properties);
33+
super(properties.isRedstoneConductor(ALWAYS).isSuffocating(ALWAYS).isViewBlocking(ALWAYS).noParticlesOnBreak());
34+
}
35+
36+
public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
37+
// For particles
38+
if(context instanceof EntityCollisionContext ec && (ec.getEntity() == null || ec.getEntity() instanceof FallingBlockEntity)) return Shapes.block();
39+
return SHAPE;
40+
}
41+
42+
public VoxelShape getBlockSupportShape(BlockState state, BlockGetter level, BlockPos pos) {
43+
return Shapes.block();
44+
}
45+
46+
public VoxelShape getVisualShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
47+
return Shapes.block();
2448
}
2549

2650
@Override
2751
public void onLand(Level level, BlockPos pos, BlockState state, BlockState other, FallingBlockEntity entity) {
2852
super.onLand(level, pos, state, other, entity);
29-
if (!entity.isSilent()) level.playSound(null, pos, OSoundEvents.BONE_PILE_FALL.get(), SoundSource.BLOCKS, 1F, 1F);
53+
if (!entity.isSilent())
54+
level.playSound(null, pos, OSoundEvents.BONE_PILE_FALL.get(), SoundSource.BLOCKS, 1F, 1F);
3055
particles(level, Vec3.atCenterOf(pos), 10);
3156
}
3257

3358
@Override
3459
public boolean addLandingEffects(BlockState state, ServerLevel level, BlockPos pos, BlockState other, LivingEntity entity, int numberOfParticles) {
35-
particles(level, entity.position(), numberOfParticles / 2);
60+
particles(level, entity.position().add(0, 0.2, 0.0), numberOfParticles / 2);
3661
return true;
3762
}
3863

3964
@Override
4065
public boolean addRunningEffects(BlockState state, Level level, BlockPos pos, Entity entity) {
41-
var vec = entity.position();
42-
level.addParticle(OParticleTypes.BONE_FRAGMENT.get(), vec.x, vec.y, vec.z, level.random.nextDouble() - 0.5, level.random.nextDouble() - 0.5, level.random.nextDouble() - 0.5);
66+
var vec = entity.position().add(0, 0.2, 0.0);
67+
var speed = entity.isSprinting() ? 0.5F : 0.2F;
68+
var halfSpeed = speed / 2;
69+
level.addParticle(OParticleTypes.BONE_FRAGMENT.get(), vec.x, vec.y, vec.z, level.random.nextDouble() * speed - halfSpeed, level.random.nextDouble() * speed - halfSpeed, level.random.nextDouble() * speed - halfSpeed);
4370
return true;
4471
}
4572

@@ -50,11 +77,11 @@ public void initializeClient(Consumer<IClientBlockExtensions> consumer) {
5077

5178
private void particles(Level level, Vec3 vec, int numberOfParticles) {
5279
if (level instanceof ServerLevel serverLevel) {
53-
serverLevel.sendParticles(OParticleTypes.BONE_FRAGMENT.get(), vec.x, vec.y, vec.z, numberOfParticles, level.random.nextDouble() - 0.5, level.random.nextDouble() - 0.5, level.random.nextDouble() - 0.5, 0.0);
80+
serverLevel.sendParticles(OParticleTypes.BONE_FRAGMENT.get(), vec.x, vec.y, vec.z, numberOfParticles, 0.35, 0.35, 0.35, 0.1);
5481
} else for (int i = 0; i < numberOfParticles; i++) {
5582
level.addParticle(OParticleTypes.BONE_FRAGMENT.get(),
5683
vec.x + level.random.nextDouble() - 0.5, vec.y + level.random.nextDouble() - 0.5, vec.z + level.random.nextDouble() - 0.5,
57-
level.random.nextDouble() - 0.5, level.random.nextDouble() - 0.5, level.random.nextDouble() - 0.5
84+
level.random.nextDouble() * 0.3 - 0.15, level.random.nextDouble() * 0.3 - 0.15, level.random.nextDouble() * 0.3 - 0.15
5885
);
5986
}
6087
}

src/main/java/galena/oreganized/content/block/SepulcherBlock.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import galena.oreganized.index.OSoundEvents;
77
import net.minecraft.Util;
88
import net.minecraft.core.BlockPos;
9+
import net.minecraft.core.particles.ParticleTypes;
10+
import net.minecraft.server.level.ServerLevel;
911
import net.minecraft.sounds.SoundSource;
1012
import net.minecraft.stats.Stats;
1113
import net.minecraft.world.InteractionHand;
@@ -16,7 +18,6 @@
1618
import net.minecraft.world.item.ItemStack;
1719
import net.minecraft.world.level.BlockGetter;
1820
import net.minecraft.world.level.Level;
19-
import net.minecraft.world.level.LevelAccessor;
2021
import net.minecraft.world.level.block.Block;
2122
import net.minecraft.world.level.block.entity.BlockEntity;
2223
import net.minecraft.world.level.block.entity.BlockEntityType;
@@ -91,12 +92,17 @@ public static boolean tryInsert(ItemStack stack, @Nullable Player player, BlockS
9192
return false;
9293
}
9394

94-
public static void insert(@Nullable Entity user, BlockState state, LevelAccessor level, BlockPos pos, int by) {
95+
public static void insert(@Nullable Entity user, BlockState state, Level level, BlockPos pos, int by) {
9596
var newState = state.setValue(LEVEL, Math.min(MAX_LEVEL, state.getValue(LEVEL) + by));
9697
level.setBlock(pos, newState, 3);
9798
level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(user, newState));
9899

99-
level.playSound(null, pos, OSoundEvents.SEPULCHER_FILLED.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
100+
if(level instanceof ServerLevel serverLevel) {
101+
var vec = Vec3.atCenterOf(pos);
102+
serverLevel.sendParticles(ParticleTypes.COMPOSTER, vec.x, vec.y, vec.z, 10, 0.3, 0.3, 0.3, 0.0);
103+
}
104+
105+
level.playSound(null, pos, OSoundEvents.SEPULCHER_FILLED.get(), SoundSource.BLOCKS, 0.5F, 1.0F);
100106
}
101107

102108
public static void extract(@Nullable Entity user, BlockState state, Level level, BlockPos pos) {

src/main/java/galena/oreganized/content/block/VigilCandleBlock.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.jetbrains.annotations.Nullable;
2929

3030
import java.util.Optional;
31+
import java.util.function.ToIntFunction;
3132

3233
import static net.minecraft.world.level.block.CandleBlock.LIT;
3334
import static net.minecraft.world.level.block.CandleBlock.MAX_CANDLES;
@@ -64,6 +65,8 @@ private static VoxelShape[] createShapes(boolean hanging) {
6465
private static final VoxelShape[] SHAPES = createShapes(false);
6566
private static final VoxelShape[] HANGING_SHAPES = createShapes(true);
6667

68+
public static final ToIntFunction<BlockState> LIGHT_EMISSION = state -> state.getValue(LIT) ? 6 * state.getValue(CANDLES) : 0;
69+
6770
public VigilCandleBlock(Properties properties) {
6871
super(properties);
6972
registerDefaultState(defaultBlockState()
@@ -89,9 +92,10 @@ public boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
8992
@Override
9093
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
9194
var candles = state.getValue(CANDLES);
92-
var handing = state.getValue(HANGING);
95+
var hanging = state.getValue(HANGING);
9396
var index = candles - 1;
94-
return (handing ? HANGING_SHAPES : SHAPES)[index];
97+
return createShapes(hanging)[index];
98+
//return (handing ? HANGING_SHAPES : SHAPES)[index];
9599
}
96100

97101
@Override

src/main/java/galena/oreganized/content/entity/SepulcherBlockEntity.java

+18-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import net.minecraft.sounds.SoundEvent;
1818
import net.minecraft.sounds.SoundSource;
1919
import net.minecraft.world.Container;
20+
import net.minecraft.world.entity.Entity;
21+
import net.minecraft.world.entity.LivingEntity;
2022
import net.minecraft.world.entity.Pose;
2123
import net.minecraft.world.entity.player.Player;
2224
import net.minecraft.world.item.ItemStack;
@@ -75,11 +77,11 @@ public void tick(BlockState state, Level level, BlockPos pos) {
7577
progress = 0;
7678

7779
if (fillLevel == SepulcherBlock.MAX_LEVEL) {
78-
sound(OSoundEvents.SEPULCHER_SEALING);
80+
sound(OSoundEvents.SEPULCHER_SEALING, 1F);
7981
} else if (nextLevel == SepulcherBlock.READY) {
80-
sound(OSoundEvents.SEPULCHER_UNSEALING);
82+
sound(OSoundEvents.SEPULCHER_UNSEALING, 1F);
8183
} else {
82-
sound(OSoundEvents.SEPULCHER_ROTTING);
84+
sound(OSoundEvents.SEPULCHER_ROTTING, 0.5F);
8385
}
8486

8587
OreganizedNetwork.CHANNEL.send(
@@ -88,9 +90,9 @@ public void tick(BlockState state, Level level, BlockPos pos) {
8890
);
8991
}
9092

91-
private void sound(Supplier<? extends SoundEvent> sound) {
93+
private void sound(Supplier<? extends SoundEvent> sound, float volume) {
9294
if (!hasLevel()) return;
93-
level.playSound(null, getBlockPos(), sound.get(), SoundSource.BLOCKS, 1F, 1F);
95+
level.playSound(null, getBlockPos(), sound.get(), SoundSource.BLOCKS, volume, 1F);
9496
}
9597

9698
private void checkHeatSource(Level level, BlockPos pos) {
@@ -113,6 +115,10 @@ public void load(CompoundTag nbt) {
113115
heated = nbt.getBoolean("heated");
114116
}
115117

118+
public static boolean wasConsumerBySepulcher(Entity entity) {
119+
return entity.getPersistentData().getBoolean(DeathListener.TAG_KEY);
120+
}
121+
116122
@Override
117123
public DeathListener getListener() {
118124
return listener;
@@ -142,7 +148,7 @@ public boolean handleGameEvent(ServerLevel level, GameEvent event, GameEvent.Con
142148

143149
var entity = context.sourceEntity();
144150
if (entity == null) return false;
145-
if (entity.getPersistentData().getBoolean(TAG_KEY)) return false;
151+
if (wasConsumerBySepulcher(entity)) return false;
146152

147153
if (!entity.getType().is(OTags.Entities.FILLS_SEPULCHER)) return false;
148154

@@ -153,17 +159,21 @@ public boolean handleGameEvent(ServerLevel level, GameEvent event, GameEvent.Con
153159

154160
entity.getPersistentData().putBoolean(TAG_KEY, true);
155161

162+
if (entity instanceof LivingEntity living && !(entity instanceof Player)) {
163+
living.skipDropExperience();
164+
}
165+
156166
SepulcherBlock.insert(null, state, level, getBlockPos(), level.random.nextIntBetweenInclusive(3, 4));
157167

158-
sound(OSoundEvents.SEPULCHER_CORPSE_STUFFED);
168+
sound(OSoundEvents.SEPULCHER_CORPSE_STUFFED, 1F);
159169

160170
OreganizedNetwork.CHANNEL.send(
161171
PacketDistributor.NEAR.with(PacketDistributor.TargetPoint.p(vec.x, vec.y, vec.z, 16.0, entity.level().dimension())),
162172
new SepulcherConsumesDeathPacket(vec)
163173
);
164174

165175
entity.setPos(Vec3.atCenterOf(getBlockPos()));
166-
if(entity.getPose() == Pose.DYING) entity.setPose(Pose.STANDING);
176+
if (entity.getPose() == Pose.DYING) entity.setPose(Pose.STANDING);
167177

168178
return true;
169179
}

src/main/java/galena/oreganized/index/OBlocks.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import net.minecraft.world.item.Item;
2929
import net.minecraft.world.level.block.Block;
3030
import net.minecraft.world.level.block.Blocks;
31-
import net.minecraft.world.level.block.CandleBlock;
3231
import net.minecraft.world.level.block.DropExperienceBlock;
3332
import net.minecraft.world.level.block.IceBlock;
3433
import net.minecraft.world.level.block.LiquidBlock;
@@ -207,10 +206,10 @@ private static BlockBehaviour.Properties leadDecoProperties() {
207206
public static final RegistryObject<Block> MOLTEN_LEAD_CAULDRON = HELPER.createBlock("molten_lead_cauldron", () -> new MoltenLeadCauldronBlock(BlockBehaviour.Properties.copy(Blocks.LAVA_CAULDRON).randomTicks()));
208207

209208
public static final RegistryObject<Block> SEPULCHER = register("sepulcher", () -> new SepulcherBlock(BlockBehaviour.Properties.copy(Blocks.CAULDRON).sound(OSoundTypes.SEPULCHER)));
210-
public static final RegistryObject<Block> BONE_PILE = register("bone_pile", () -> new BonePileBlock(BlockBehaviour.Properties.copy(Blocks.BONE_BLOCK).sound(OSoundTypes.BONE_PILE).noParticlesOnBreak()));
209+
public static final RegistryObject<Block> BONE_PILE = register("bone_pile", () -> new BonePileBlock(BlockBehaviour.Properties.copy(Blocks.BONE_BLOCK).sound(OSoundTypes.BONE_PILE).strength(1F)));
211210
public static final RegistryObject<Block> ROTTING_FLESH = HELPER.createBlock("rotting_flesh", () -> new Block(BlockBehaviour.Properties.copy(Blocks.DIRT)));
212211

213-
private static final Supplier<BlockBehaviour.Properties> VIGIL_CANDLE_PROPERTIES = () -> BlockBehaviour.Properties.of().lightLevel(CandleBlock.LIGHT_EMISSION).sound(SoundType.METAL).pushReaction(PushReaction.DESTROY);
212+
private static final Supplier<BlockBehaviour.Properties> VIGIL_CANDLE_PROPERTIES = () -> BlockBehaviour.Properties.of().lightLevel(VigilCandleBlock.LIGHT_EMISSION).sound(SoundType.METAL).pushReaction(PushReaction.DESTROY);
214213
public static final RegistryObject<Block> VIGIL_CANDLE = register("vigil_candle", () -> new VigilCandleBlock(VIGIL_CANDLE_PROPERTIES.get()));
215214
public static final Map<DyeColor, RegistryObject<Block>> COLORED_VIGIL_CANDLES = registerColored("vigil_candle", color -> new VigilCandleBlock(VIGIL_CANDLE_PROPERTIES.get().mapColor(color)));
216215

src/main/java/galena/oreganized/index/OParticleTypes.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package galena.oreganized.index;
22

33
import galena.oreganized.Oreganized;
4+
import galena.oreganized.client.particle.BoneFragmentParticle;
45
import galena.oreganized.client.particle.CustomDrippingParticle;
56
import galena.oreganized.client.particle.KineticHitParticle;
67
import galena.oreganized.client.particle.LeadCloudParticleProvider;
@@ -9,7 +10,6 @@
910
import net.minecraft.client.Minecraft;
1011
import net.minecraft.client.particle.ExplodeParticle;
1112
import net.minecraft.client.particle.ParticleEngine;
12-
import net.minecraft.client.particle.SplashParticle;
1313
import net.minecraft.core.particles.ParticleType;
1414
import net.minecraft.core.particles.SimpleParticleType;
1515
import net.minecraftforge.api.distmarker.Dist;
@@ -49,6 +49,6 @@ public static void registerParticleFactories(RegisterParticleProvidersEvent even
4949
engine.register(LEAD_CLOUD.get(), LeadCloudParticleProvider::new);
5050
engine.register(LEAD_BLOW.get(), ExplodeParticle.Provider::new);
5151
engine.register(LEAD_BLOW.get(), ExplodeParticle.Provider::new);
52-
engine.register(BONE_FRAGMENT.get(), SplashParticle.Provider::new);
52+
engine.register(BONE_FRAGMENT.get(), BoneFragmentParticle.Provider::new);
5353
}
5454
}

src/main/java/galena/oreganized/index/OSoundTypes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
import net.minecraftforge.common.util.ForgeSoundType;
55

66
public class OSoundTypes {
7-
public static final SoundType BONE_PILE = new ForgeSoundType(1.0F, 1.0F, OSoundEvents.BONE_PILE_BREAK, OSoundEvents.BONE_PILE_STEP, OSoundEvents.BONE_PILE_PLACE, OSoundEvents.BONE_PILE_HIT, OSoundEvents.BONE_PILE_FALL);
7+
public static final SoundType BONE_PILE = new ForgeSoundType(1.5F, 1.0F, OSoundEvents.BONE_PILE_BREAK, OSoundEvents.BONE_PILE_STEP, OSoundEvents.BONE_PILE_PLACE, OSoundEvents.BONE_PILE_HIT, OSoundEvents.BONE_PILE_FALL);
88
public static final SoundType SEPULCHER = new ForgeSoundType(1.0F, 1.0F, OSoundEvents.SEPULCHER_BREAK, OSoundEvents.SEPULCHER_STEP, OSoundEvents.SEPULCHER_PLACE, OSoundEvents.SEPULCHER_HIT, OSoundEvents.SEPULCHER_FALL);
99
}

src/main/java/galena/oreganized/mixin/EntityMixin.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package galena.oreganized.mixin;
22

3+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
4+
import galena.oreganized.index.OBlocks;
35
import galena.oreganized.world.IMotionHolder;
46
import net.minecraft.world.entity.Entity;
57
import org.spongepowered.asm.mixin.Mixin;
@@ -9,7 +11,7 @@
911
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1012

1113
@Mixin(Entity.class)
12-
public class EntityMixin implements IMotionHolder {
14+
public abstract class EntityMixin implements IMotionHolder {
1315

1416
@Unique
1517
private double oreganized$Motion = 0.0;
@@ -29,4 +31,17 @@ private void updateMotion(CallbackInfo ci) {
2931
public double oreganised$getMotion() {
3032
return oreganized$Motion;
3133
}
34+
35+
@ModifyExpressionValue(
36+
method = "canSpawnSprintParticle()Z",
37+
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;isSprinting()Z")
38+
)
39+
public boolean isSprinting(boolean original) {
40+
var self = (Entity) (Object) this;
41+
return original || (
42+
self.level().getBlockState(self.getBlockPosBelowThatAffectsMyMovement()).is(OBlocks.BONE_PILE.get())
43+
&& (self.getDeltaMovement().x != 0.0 || self.getDeltaMovement().z != 0.0)
44+
);
45+
}
46+
3247
}

0 commit comments

Comments
 (0)