Working particles on Polymer!

This commit is contained in:
Martin Prokoph
2024-07-31 12:01:59 +02:00
parent 0b32c5afc1
commit 01fa068af6
7 changed files with 56 additions and 31 deletions

View File

@@ -119,21 +119,21 @@ public class DecorativeMain implements ModInitializer {
ItemGroup group;
Text name = Text.translatable("itemGroup."+id.getNamespace()+"."+id.getPath());
if (DecorativeConfig.polymerIntegration) {
//if (DecorativeConfig.polymerIntegration) {
group = PolymerItemGroupUtils.builder().displayName(name).icon(() -> new ItemStack(icon)).entries(((displayContext, entries) -> {
List<ItemStack> groupItems = new ArrayList<>();
RegistryUtil.groupItems.stream().filter(itemEntry -> itemEntry.groupName() == name).forEach(itemEntry -> groupItems.add(itemEntry.stack()));
entries.addAll(groupItems);
})).build();
PolymerItemGroupUtils.registerPolymerItemGroup(id, group);
} else {
group = FabricItemGroup.builder().displayName(name).icon(() -> new ItemStack(icon)).entries(((displayContext, entries) -> {
List<ItemStack> groupItems = new ArrayList<>();
RegistryUtil.groupItems.stream().filter(itemEntry -> itemEntry.groupName() == name).forEach(itemEntry -> groupItems.add(itemEntry.stack()));
entries.addAll(groupItems);
})).build();
Registry.register(Registries.ITEM_GROUP, id, group);
}
// } else {
// group = FabricItemGroup.builder().displayName(name).icon(() -> new ItemStack(icon)).entries(((displayContext, entries) -> {
// List<ItemStack> groupItems = new ArrayList<>();
// RegistryUtil.groupItems.stream().filter(itemEntry -> itemEntry.groupName() == name).forEach(itemEntry -> groupItems.add(itemEntry.stack()));
// entries.addAll(groupItems);
// })).build();
// Registry.register(Registries.ITEM_GROUP, id, group);
// }
return group;
}
}

View File

@@ -2,10 +2,13 @@ package eu.midnightdust.motschen.decorative.block.blockentity;
import eu.midnightdust.motschen.decorative.block.PoolSprinkler;
import eu.midnightdust.motschen.decorative.init.BlockEntities;
import eu.midnightdust.motschen.decorative.util.ParticleUtil;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class PoolSprinklerBlockEntity extends BlockEntity {
@@ -15,14 +18,15 @@ public class PoolSprinklerBlockEntity extends BlockEntity {
}
public static void tick(World world, BlockPos pos, BlockState state, PoolSprinklerBlockEntity blockEntity) {
if (state.get(PoolSprinkler.POWERED)) {
switch (state.get(PoolSprinkler.FACING)) {
case NORTH: world.addParticle(ParticleTypes.DRIPPING_WATER, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() - 0.34, 1, 1, 1); break;
case EAST: world.addParticle(ParticleTypes.DRIPPING_WATER, pos.getX() + 1.34, pos.getY() + 0.5, pos.getZ() + 0.5, 1, 1, 1); break;
case SOUTH: world.addParticle(ParticleTypes.DRIPPING_WATER, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 1.34, 1, 1, 1); break;
case WEST: world.addParticle(ParticleTypes.DRIPPING_WATER, pos.getX() - 0.34, pos.getY() + 0.5, pos.getZ() + 0.5, 1, 1, 1); break;
default: break;
}
if (state.get(PoolSprinkler.POWERED) && !world.isClient) {
Vec3d particlePos = switch (state.get(PoolSprinkler.FACING)) {
case NORTH -> new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() - 0.34);
case EAST -> new Vec3d(pos.getX() + 1.34, pos.getY() + 0.5, pos.getZ() + 0.5);
case SOUTH -> new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 1.34);
case WEST -> new Vec3d(pos.getX() - 0.34, pos.getY() + 0.5, pos.getZ() + 0.5);
default -> Vec3d.ZERO;
};
PlayerLookup.tracking(blockEntity).forEach(watchingPlayer -> ParticleUtil.spawnParticle(watchingPlayer, ParticleTypes.DRIPPING_WATER, particlePos, new Vec3d(0, 0, 0), 1));
}
}
}

View File

@@ -1,11 +1,14 @@
package eu.midnightdust.motschen.decorative.block.blockentity;
import eu.midnightdust.motschen.decorative.block.PoolSprinkler;
import eu.midnightdust.motschen.decorative.block.ShowerHead;
import eu.midnightdust.motschen.decorative.init.BlockEntities;
import eu.midnightdust.motschen.decorative.util.ParticleUtil;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class ShowerHeadBlockEntity extends BlockEntity {
@@ -15,14 +18,15 @@ public class ShowerHeadBlockEntity extends BlockEntity {
}
public static void tick(World world, BlockPos pos, BlockState state, ShowerHeadBlockEntity blockEntity) {
if (state.get(PoolSprinkler.POWERED)) {
switch (state.get(PoolSprinkler.FACING)) {
case NORTH: world.addParticle(ParticleTypes.DRIPPING_WATER, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.625, 1, 1, 1); break;
case EAST: world.addParticle(ParticleTypes.DRIPPING_WATER, pos.getX() + 0.375, pos.getY() + 0.5, pos.getZ() + 0.5, 1, 1, 1); break;
case SOUTH: world.addParticle(ParticleTypes.DRIPPING_WATER, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.375, 1, 1, 1); break;
case WEST: world.addParticle(ParticleTypes.DRIPPING_WATER, pos.getX() + 0.625, pos.getY() + 0.5, pos.getZ() + 0.5, 1, 1, 1); break;
default: break;
}
if (state.get(ShowerHead.POWERED) && !world.isClient) {
Vec3d particlePos = switch (state.get(ShowerHead.FACING)) {
case NORTH -> new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.625);
case EAST -> new Vec3d(pos.getX() + 0.375, pos.getY() + 0.5, pos.getZ() + 0.5);
case SOUTH -> new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.375);
case WEST -> new Vec3d(pos.getX() + 0.625, pos.getY() + 0.5, pos.getZ() + 0.5);
default -> Vec3d.ZERO;
};
PlayerLookup.tracking(blockEntity).forEach(watchingPlayer -> ParticleUtil.spawnParticle(watchingPlayer, ParticleTypes.DRIPPING_WATER, particlePos, new Vec3d(1, 0, 1), 1));
}
}

View File

@@ -32,7 +32,8 @@ public class BlockEntities {
}
private static <T extends BlockEntity> BlockEntityType<T> registerBlockEntity(Identifier id, BlockEntityType.BlockEntityFactory<T> factory, Block... blocks) {
var blockEntity = Registry.register(Registries.BLOCK_ENTITY_TYPE, id, BlockEntityType.Builder.create(factory, blocks).build(null));
if (DecorativeConfig.polymerIntegration) PolymerBlockUtils.registerBlockEntity(blockEntity);
//if (DecorativeConfig.polymerIntegration)
PolymerBlockUtils.registerBlockEntity(blockEntity);
return blockEntity;
}
}

View File

@@ -73,7 +73,7 @@ public class DirectionalItemDisplayModel extends BlockModel {
public float getRotation(BlockState state) {
if (state.getBlock() instanceof FireHydrant) return state.get(FireHydrant.FACING).getHorizontal() * -90;
else if (state.getBlock() instanceof WaterPump) return state.get(WaterPump.FACING).getHorizontal() * -90 - 90;
else if (state.getBlock() instanceof PoolSprinkler) return state.get(PoolSprinkler.FACING).getHorizontal() * -90;
else if (state.getBlock() instanceof PoolSprinkler) return state.get(PoolSprinkler.FACING).getHorizontal() * -90 - 90;
else if (state.getBlock() instanceof ShowerHead) return state.get(ShowerHead.FACING).getHorizontal() * -90 + 90;
else if (state.getBlock() instanceof Sign) return state.get(PoolSprinkler.FACING).getHorizontal() * -90 + 180;
else return state.get(Guardrail.FACING).getHorizontal() * -90;

View File

@@ -0,0 +1,15 @@
package eu.midnightdust.motschen.decorative.util;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.Vec3d;
public class ParticleUtil {
public static void spawnParticle(ServerPlayerEntity player, ParticleType<?> type, Vec3d pos, Vec3d offset, float speed) {
ServerPlayNetworking.getSender(player).sendPacket(new ParticleS2CPacket((ParticleEffect) type, false, pos.x, pos.y, pos.z,
(float) offset.x / 16f, (float) offset.y / 16f, (float) offset.z / 16f, speed, 1));
}
}

View File

@@ -45,11 +45,12 @@ public class RegistryUtil {
}
public static Item blockItem(Block block) {
if (DecorativeConfig.polymerIntegration) {
//if (DecorativeConfig.polymerIntegration) {
if (block instanceof PolymerBlock) return new FactoryBlockItem((Block & PolymerBlock) block, new Item.Settings());
else System.out.println(block);
}
return new BlockItem(block, new Item.Settings());
//}
return null;
//return new BlockItem(block, new Item.Settings());
}
public static void registerItem(Identifier id, Item item, ItemGroup group) {