revert: 1.21.1 backport

This commit is contained in:
Martin Prokoph
2025-03-26 12:44:20 +01:00
parent e48f37c269
commit 9d770a64dd
227 changed files with 839 additions and 284 deletions

View File

@@ -4,10 +4,8 @@ import eu.midnightdust.motschen.rocks.blockstates.StarfishVariation;
import eu.midnightdust.motschen.rocks.networking.HelloPayload;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import java.util.Objects;
@@ -18,10 +16,10 @@ public class RocksClient implements ClientModInitializer {
public void onInitializeClient() {
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> sender.sendPacket(new HelloPayload()));
for (StarfishVariation variation : StarfishVariation.values()) {
ModelPredicateProviderRegistry.register(RocksMain.Starfish.asItem(), Identifier.of(variation.toString()),
(stack, world, entity, seed) -> matchesVariation(stack, variation));
}
// for (StarfishVariation variation : StarfishVariation.values()) {
// ModelPredicateProviderRegistry.register(RocksMain.Starfish.asItem(), Identifier.of(variation.toString()),
// (stack, world, entity, seed) -> matchesVariation(stack, variation));
// }
}
private static Integer matchesVariation(ItemStack stack, StarfishVariation variation) {
var blockStateData = stack.getComponents().get(DataComponentTypes.BLOCK_STATE);

View File

@@ -25,6 +25,8 @@ public class RocksDataGen implements DataGeneratorEntrypoint {
pack.addProvider(Recipes::new);
pack.addProvider(Language.English::new);
pack.addProvider(Language.German::new);
pack.addProvider(Models::new);
}
@Override
public String getEffectiveModId() {
@@ -52,8 +54,8 @@ public class RocksDataGen implements DataGeneratorEntrypoint {
@Override
protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) {
entries.addAll(registries.getWrapperOrThrow(RegistryKeys.CONFIGURED_FEATURE));
entries.addAll(registries.getWrapperOrThrow(RegistryKeys.PLACED_FEATURE));
entries.addAll(registries.getOrThrow(RegistryKeys.CONFIGURED_FEATURE));
entries.addAll(registries.getOrThrow(RegistryKeys.PLACED_FEATURE));
}
@Override

View File

@@ -128,7 +128,7 @@ public class RocksMain implements ModInitializer {
public static Item simpleItem(Identifier id) {
if (polymerMode) return PolyUtil.simplePolymerItem(id);
return new Item(new Item.Settings());
return new Item(new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id)));
}
public static void registerItemGroup() {

View File

@@ -30,7 +30,7 @@ public class NetherGeyser extends BlockWithEntity implements BlockEntityProvider
public static final BooleanProperty ACTIVE = BooleanProperty.of("active");
public NetherGeyser(Identifier blockId) {
super(AbstractBlock.Settings.copy(Blocks.STONE).strength(10).noCollision().dynamicBounds().nonOpaque().sounds(BlockSoundGroup.STONE));
super(AbstractBlock.Settings.copy(Blocks.STONE).registryKey(RegistryKey.of(RegistryKeys.BLOCK, blockId)).strength(10).noCollision().dynamicBounds().nonOpaque().sounds(BlockSoundGroup.STONE));
this.setDefaultState(this.stateManager.getDefaultState().with(ACTIVE, false));
}

View File

@@ -8,6 +8,8 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
@@ -32,7 +34,7 @@ public class OverworldGeyser extends BlockWithEntity implements BlockEntityProvi
public static final BooleanProperty SNOWY = Properties.SNOWY;
public OverworldGeyser(Identifier blockId) {
super(AbstractBlock.Settings.copy(Blocks.STONE).strength(10).noCollision().dynamicBounds().nonOpaque().sounds(BlockSoundGroup.STONE));
super(AbstractBlock.Settings.copy(Blocks.STONE).registryKey(RegistryKey.of(RegistryKeys.BLOCK, blockId)).strength(10).noCollision().dynamicBounds().nonOpaque().sounds(BlockSoundGroup.STONE));
this.setDefaultState(this.stateManager.getDefaultState().with(ACTIVE, false).with(SNOWY, false));
}

View File

@@ -2,21 +2,24 @@ package eu.midnightdust.motschen.rocks.block;
import net.minecraft.block.*;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.tick.ScheduledTickView;
public class Pinecone extends Block {
private static final VoxelShape SHAPE;
public Pinecone(Identifier blockId) {
super(AbstractBlock.Settings.copy(Blocks.POPPY).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.WOOD));
super(AbstractBlock.Settings.copy(Blocks.POPPY).registryKey(RegistryKey.of(RegistryKeys.BLOCK, blockId)).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.WOOD));
this.setDefaultState(this.stateManager.getDefaultState());
}
@@ -32,11 +35,11 @@ public class Pinecone extends Block {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
public BlockState getStateForNeighborUpdate(BlockState state, WorldView world, ScheduledTickView tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, Random random) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, world, tickView, pos, direction, neighborPos, neighborState, random);
}
@Override
protected boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {return true;}
protected boolean isTransparent(BlockState state) {return true;}
@Override
protected boolean canReplace(BlockState state, ItemPlacementContext context) {return true;}
}

View File

@@ -5,19 +5,24 @@ import eu.midnightdust.motschen.rocks.blockstates.RockVariation;
import net.minecraft.block.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.tick.ScheduledTickView;
import java.util.Objects;
@@ -28,7 +33,7 @@ public class Rock extends Block {
private static final EnumProperty<RockVariation> ROCK_VARIATION = RocksMain.ROCK_VARIATION;
public Rock(Identifier blockId) {
super(AbstractBlock.Settings.copy(Blocks.POPPY).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.STONE));
super(AbstractBlock.Settings.copy(Blocks.POPPY).registryKey(RegistryKey.of(RegistryKeys.BLOCK, blockId)).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.STONE));
this.setDefaultState(this.stateManager.getDefaultState().with(ROCK_VARIATION, RockVariation.TINY));
}
@@ -64,11 +69,11 @@ public class Rock extends Block {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
public BlockState getStateForNeighborUpdate(BlockState state, WorldView world, ScheduledTickView tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, Random random) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, world, tickView, pos, direction, neighborPos, neighborState, random);
}
@Override
protected boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {return true;}
protected boolean isTransparent(BlockState state) {return true;}
@Override
protected boolean canReplace(BlockState state, ItemPlacementContext context) {return true;}
}

View File

@@ -7,6 +7,8 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
@@ -17,11 +19,12 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.tick.ScheduledTickView;
import java.util.Objects;
@@ -32,7 +35,7 @@ public class Seashell extends Block implements Waterloggable {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public Seashell(Identifier blockId) {
super(AbstractBlock.Settings.copy(Blocks.POPPY).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.STONE));
super(AbstractBlock.Settings.copy(Blocks.POPPY).registryKey(RegistryKey.of(RegistryKeys.BLOCK, blockId)).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.STONE));
this.setDefaultState(this.stateManager.getDefaultState().with(SEASHELL_VARIATION, SeashellVariation.PINK).with(WATERLOGGED, false));
}
@@ -75,8 +78,8 @@ public class Seashell extends Block implements Waterloggable {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
public BlockState getStateForNeighborUpdate(BlockState state, WorldView world, ScheduledTickView tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, Random random) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, world, tickView, pos, direction, neighborPos, neighborState, random);
}
@Override
protected boolean canReplace(BlockState state, ItemPlacementContext context) {return true;}

View File

@@ -11,6 +11,8 @@ import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
@@ -21,14 +23,17 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.tick.ScheduledTickView;
import java.util.Objects;
import static eu.midnightdust.motschen.rocks.RocksMain.id;
public class Starfish extends Block implements Waterloggable {
private static final VoxelShape SHAPE;
@@ -36,7 +41,7 @@ public class Starfish extends Block implements Waterloggable {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public Starfish(Identifier blockId) {
super(AbstractBlock.Settings.copy(Blocks.POPPY).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.CORAL));
super(AbstractBlock.Settings.copy(Blocks.POPPY).registryKey(RegistryKey.of(RegistryKeys.BLOCK, blockId)).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.CORAL));
this.setDefaultState(this.stateManager.getDefaultState().with(STARFISH_VARIATION, StarfishVariation.RED).with(WATERLOGGED, false));
}
@@ -53,9 +58,9 @@ public class Starfish extends Block implements Waterloggable {
.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
}
@Override
public ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state) {
public ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state, boolean includeData) {
ItemStack stack = new ItemStack(this);
stack.applyComponentsFrom(ComponentMap.builder().add(DataComponentTypes.BLOCK_STATE, BlockStateComponent.DEFAULT.with(STARFISH_VARIATION, state.get(STARFISH_VARIATION))).build());
stack.applyComponentsFrom(ComponentMap.builder().add(DataComponentTypes.ITEM_MODEL, id("starfish")).add(DataComponentTypes.BLOCK_STATE, BlockStateComponent.DEFAULT.with(STARFISH_VARIATION, state.get(STARFISH_VARIATION))).build());
return stack;
}
@@ -84,8 +89,8 @@ public class Starfish extends Block implements Waterloggable {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
public BlockState getStateForNeighborUpdate(BlockState state, WorldView world, ScheduledTickView tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, Random random) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, world, tickView, pos, direction, neighborPos, neighborState, random);
}
@Override
protected boolean canReplace(BlockState state, ItemPlacementContext context) {return true;}

View File

@@ -5,6 +5,8 @@ import eu.midnightdust.motschen.rocks.blockstates.StickVariation;
import net.minecraft.block.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
@@ -15,11 +17,12 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.tick.ScheduledTickView;
import java.util.Objects;
@@ -30,7 +33,7 @@ public class Stick extends Block {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public Stick(Identifier blockId) {
super(AbstractBlock.Settings.copy(Blocks.POPPY).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.WOOD));
super(AbstractBlock.Settings.copy(Blocks.POPPY).registryKey(RegistryKey.of(RegistryKeys.BLOCK, blockId)).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.WOOD));
this.setDefaultState(this.stateManager.getDefaultState().with(STICK_VARIATION, StickVariation.SMALL).with(WATERLOGGED, false));
}
@@ -66,11 +69,11 @@ public class Stick extends Block {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
public BlockState getStateForNeighborUpdate(BlockState state, WorldView world, ScheduledTickView tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, Random random) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, world, tickView, pos, direction, neighborPos, neighborState, random);
}
@Override
protected boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {return true;}
protected boolean isTransparent(BlockState state) {return true;}
@Override
protected boolean canReplace(BlockState state, ItemPlacementContext context) {return true;}
}

View File

@@ -32,9 +32,9 @@ public class NetherGeyserBlockEntity extends BlockEntity {
world.setBlockState(pos, state.with(NetherGeyser.ACTIVE, true));
if (RocksConfig.netherGeyserDamage && world instanceof ServerWorld serverWorld) {
player.damage(world.getDamageSources().onFire(), 1);
player.damage(serverWorld, world.getDamageSources().onFire(), 1);
if (player2 != null) {
player2.damage(world.getDamageSources().onFire(), 4);
player2.damage(serverWorld, world.getDamageSources().onFire(), 4);
}
}
blockEntity.countdown = 1000;

View File

@@ -27,13 +27,13 @@ public class NetherGeyserPolymer extends NetherGeyser implements PolymerBlock, P
return PolyUtil.SMALL_BLOCK;
}
@Override
public BlockState getPolymerBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : getPolymerBlockState(state);
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : getPolymerBlockState(state);
}
@Override
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : Blocks.NETHERRACK.getDefaultState();
public BlockState getPolymerBreakEventBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : Blocks.NETHERRACK.getDefaultState();
}
@Override
@@ -42,6 +42,6 @@ public class NetherGeyserPolymer extends NetherGeyser implements PolymerBlock, P
}
@Override
public boolean canSyncRawToClient(ServerPlayerEntity player) {return hasModOnClient(player);}
public boolean canSyncRawToClient(PacketContext context) {return hasModOnClient(context.getPlayer());}
}

View File

@@ -27,13 +27,13 @@ public class OverworldGeyserPolymer extends OverworldGeyser implements PolymerBl
return state.get(SNOWY) ? Blocks.SNOW.getDefaultState() : PolyUtil.SMALL_BLOCK;
}
@Override
public BlockState getPolymerBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : getPolymerBlockState(state);
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : getPolymerBlockState(state);
}
@Override
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : Blocks.SNOW.getDefaultState();
public BlockState getPolymerBreakEventBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : Blocks.SNOW.getDefaultState();
}
@Override
@@ -42,7 +42,7 @@ public class OverworldGeyserPolymer extends OverworldGeyser implements PolymerBl
}
@Override
public boolean canSyncRawToClient(ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -29,13 +29,13 @@ public class PineconePolymer extends Pinecone implements PolymerBlock, PolymerTe
return PolyUtil.SMALL_BLOCK;
}
@Override
public BlockState getPolymerBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : getPolymerBlockState(state);
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : getPolymerBlockState(state);
}
@Override
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : Blocks.SPRUCE_BUTTON.getDefaultState().with(Properties.BLOCK_FACE, BlockFace.FLOOR);
public BlockState getPolymerBreakEventBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : Blocks.SPRUCE_BUTTON.getDefaultState().with(Properties.BLOCK_FACE, BlockFace.FLOOR);
}
@Override
@@ -44,7 +44,7 @@ public class PineconePolymer extends Pinecone implements PolymerBlock, PolymerTe
}
@Override
public boolean canSyncRawToClient(ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -16,6 +16,7 @@ import net.minecraft.state.property.Properties;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.packettweaker.PacketContext;
import static eu.midnightdust.motschen.rocks.util.polymer.PolyUtil.hasModOnClient;
@@ -28,13 +29,13 @@ public class RockPolymer extends Rock implements PolymerBlock, PolymerTexturedBl
return PolyUtil.SMALL_BLOCK;
}
@Override
public BlockState getPolymerBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : getPolymerBlockState(state);
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : getPolymerBlockState(state);
}
@Override
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : Blocks.STONE_BUTTON.getDefaultState().with(Properties.BLOCK_FACE, BlockFace.FLOOR);
public BlockState getPolymerBreakEventBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : Blocks.STONE_BUTTON.getDefaultState().with(Properties.BLOCK_FACE, BlockFace.FLOOR);
}
@Override
@@ -43,7 +44,7 @@ public class RockPolymer extends Rock implements PolymerBlock, PolymerTexturedBl
}
@Override
public boolean canSyncRawToClient(ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -28,13 +28,13 @@ public class SeashellPolymer extends Seashell implements PolymerBlock, PolymerTe
else return PolyUtil.SMALL_BLOCK;
}
@Override
public BlockState getPolymerBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : getPolymerBlockState(state);
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : getPolymerBlockState(state);
}
@Override
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : Blocks.WHITE_CANDLE.getDefaultState();
public BlockState getPolymerBreakEventBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : Blocks.WHITE_CANDLE.getDefaultState();
}
@Override
@@ -43,7 +43,7 @@ public class SeashellPolymer extends Seashell implements PolymerBlock, PolymerTe
}
@Override
public boolean canSyncRawToClient(ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -28,13 +28,13 @@ public class StarfishPolymer extends Starfish implements PolymerBlock, PolymerTe
else return PolyUtil.SMALL_BLOCK;
}
@Override
public BlockState getPolymerBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : getPolymerBlockState(state);
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : getPolymerBlockState(state);
}
@Override
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : Blocks.SEA_PICKLE.getDefaultState();
public BlockState getPolymerBreakEventBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : Blocks.SEA_PICKLE.getDefaultState();
}
@Override
@@ -43,7 +43,7 @@ public class StarfishPolymer extends Starfish implements PolymerBlock, PolymerTe
}
@Override
public boolean canSyncRawToClient(ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -29,13 +29,13 @@ public class StickPolymer extends Stick implements PolymerBlock, PolymerTextured
return PolyUtil.SMALL_BLOCK;
}
@Override
public BlockState getPolymerBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : getPolymerBlockState(state);
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : getPolymerBlockState(state);
}
@Override
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
return hasModOnClient(player) ? state : Blocks.OAK_BUTTON.getDefaultState().with(Properties.BLOCK_FACE, BlockFace.FLOOR);
public BlockState getPolymerBreakEventBlockState(BlockState state, PacketContext context) {
return hasModOnClient(context.getPlayer()) ? state : Blocks.OAK_BUTTON.getDefaultState().with(Properties.BLOCK_FACE, BlockFace.FLOOR);
}
@Override
@@ -44,7 +44,7 @@ public class StickPolymer extends Stick implements PolymerBlock, PolymerTextured
}
@Override
public boolean canSyncRawToClient(ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -3,7 +3,6 @@ package eu.midnightdust.motschen.rocks.block.polymer.model;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.block.NetherGeyser;
import eu.midnightdust.motschen.rocks.config.RocksConfig;
import eu.pb4.factorytools.api.resourcepack.BaseItemProvider;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment;
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment;
@@ -23,7 +22,7 @@ public class ItemDisplayNetherGeyserModel extends ConditionalBlockModel {
public static ItemStack NETHER;
public static void initModels() {
NETHER = BaseItemProvider.requestModel(RocksMain.id("block/nether_geyser_off"));
NETHER = ItemDisplayElementUtil.getModel(RocksMain.id("block/nether_geyser_off"));
}
public ItemDisplayNetherGeyserModel(BlockState state, BlockPos pos) {
@@ -31,6 +30,7 @@ public class ItemDisplayNetherGeyserModel extends ConditionalBlockModel {
this.main.setDisplaySize(1, 1);
this.main.setScale(new Vector3f(2));
int rotation = pos.hashCode() % 360;
System.out.println(pos.hashCode() + " " + rotation + " " + pos.hashCode() % 360);
this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(rotation));
this.main.setViewRange(0.75f * (RocksConfig.polymerViewDistance / 100f));
this.addElement(this.main);

View File

@@ -3,7 +3,6 @@ package eu.midnightdust.motschen.rocks.block.polymer.model;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.block.OverworldGeyser;
import eu.midnightdust.motschen.rocks.config.RocksConfig;
import eu.pb4.factorytools.api.resourcepack.BaseItemProvider;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment;
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment;
@@ -24,7 +23,7 @@ public class ItemDisplayOverworldGeyserModel extends ConditionalBlockModel {
public static ItemStack OVERWORLD;
public static void initModels() {
OVERWORLD = BaseItemProvider.requestModel(RocksMain.id("block/geyser_off"));
OVERWORLD = ItemDisplayElementUtil.getModel(RocksMain.id("block/geyser_off"));
}
public ItemDisplayOverworldGeyserModel(BlockState state, BlockPos pos) {

View File

@@ -2,7 +2,6 @@ package eu.midnightdust.motschen.rocks.block.polymer.model;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.config.RocksConfig;
import eu.pb4.factorytools.api.resourcepack.BaseItemProvider;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement;
import net.minecraft.block.BlockState;
@@ -17,7 +16,7 @@ public class ItemDisplayPineconeModel extends ConditionalBlockModel {
private static ItemStack PINECONE_MODEL;
public static void initModels() {
PINECONE_MODEL = BaseItemProvider.requestModel(RocksMain.id("block/pinecone"));
PINECONE_MODEL = ItemDisplayElementUtil.getModel(RocksMain.id("block/pinecone"));
}
public ItemDisplayPineconeModel(BlockState state, BlockPos pos) {

View File

@@ -3,7 +3,6 @@ package eu.midnightdust.motschen.rocks.block.polymer.model;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.config.RocksConfig;
import eu.midnightdust.motschen.rocks.util.RockType;
import eu.pb4.factorytools.api.resourcepack.BaseItemProvider;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment;
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment;
@@ -25,7 +24,7 @@ public class ItemDisplayRockModel extends ConditionalBlockModel {
for (RockType type : RockType.values()) {
var stacks = new ItemStack[4];
for (int i = 0; i < 4; i++) {
stacks[i] = BaseItemProvider.requestModel(RocksMain.id("block/"+type.getVariations()[i].getPath()));
stacks[i] = ItemDisplayElementUtil.getModel(RocksMain.id("block/"+type.getVariations()[i].getPath()));
}
models.put(type, stacks);
}

View File

@@ -2,7 +2,6 @@ package eu.midnightdust.motschen.rocks.block.polymer.model;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.config.RocksConfig;
import eu.pb4.factorytools.api.resourcepack.BaseItemProvider;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment;
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment;
@@ -20,9 +19,9 @@ public class ItemDisplaySeashellModel extends ConditionalBlockModel {
public static ItemStack YELLOW;
public static void initModels() {
PINK = BaseItemProvider.requestModel(RocksMain.id("block/seashell_pink"));
WHITE = BaseItemProvider.requestModel(RocksMain.id("block/seashell_white"));
YELLOW = BaseItemProvider.requestModel(RocksMain.id("block/seashell_yellow"));
PINK = ItemDisplayElementUtil.getModel(RocksMain.id("block/seashell_pink"));
WHITE = ItemDisplayElementUtil.getModel(RocksMain.id("block/seashell_white"));
YELLOW = ItemDisplayElementUtil.getModel(RocksMain.id("block/seashell_yellow"));
}
public ItemDisplaySeashellModel(BlockState state, BlockPos pos) {

View File

@@ -2,7 +2,6 @@ package eu.midnightdust.motschen.rocks.block.polymer.model;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.config.RocksConfig;
import eu.pb4.factorytools.api.resourcepack.BaseItemProvider;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment;
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment;
@@ -29,12 +28,12 @@ public class ItemDisplayStarfishModel extends ConditionalBlockModel {
public static ItemStack PINK_FIRST;
public static void initModels() {
RED = BaseItemProvider.requestModel(polymerId("block/starfish_red_arm"));
ORANGE = BaseItemProvider.requestModel(polymerId("block/starfish_orange_arm"));
PINK = BaseItemProvider.requestModel(polymerId("block/starfish_pink_arm"));
RED_FIRST = BaseItemProvider.requestModel(polymerId("block/starfish_red_first_arm"));
ORANGE_FIRST = BaseItemProvider.requestModel(polymerId("block/starfish_orange_first_arm"));
PINK_FIRST = BaseItemProvider.requestModel(polymerId("block/starfish_pink_first_arm"));
RED = ItemDisplayElementUtil.getModel(polymerId("block/starfish_red_arm"));
ORANGE = ItemDisplayElementUtil.getModel(polymerId("block/starfish_orange_arm"));
PINK = ItemDisplayElementUtil.getModel(polymerId("block/starfish_pink_arm"));
RED_FIRST = ItemDisplayElementUtil.getModel(polymerId("block/starfish_red_first_arm"));
ORANGE_FIRST = ItemDisplayElementUtil.getModel(polymerId("block/starfish_orange_first_arm"));
PINK_FIRST = ItemDisplayElementUtil.getModel(polymerId("block/starfish_pink_first_arm"));
}
public ItemDisplayStarfishModel(BlockState state, BlockPos pos) {

View File

@@ -3,7 +3,6 @@ package eu.midnightdust.motschen.rocks.block.polymer.model;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.config.RocksConfig;
import eu.midnightdust.motschen.rocks.util.StickType;
import eu.pb4.factorytools.api.resourcepack.BaseItemProvider;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment;
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment;
@@ -25,7 +24,7 @@ public class ItemDisplayStickModel extends ConditionalBlockModel {
for (StickType type : StickType.values()) {
var stacks = new ItemStack[3];
for (int i = 0; i < 3; i++) {
stacks[i] = BaseItemProvider.requestModel(RocksMain.id("block/"+type.getVariations()[i].getPath()));
stacks[i] = ItemDisplayElementUtil.getModel(RocksMain.id("block/"+type.getVariations()[i].getPath()));
}
models.put(type, stacks);
}

View File

@@ -52,7 +52,7 @@ public abstract class Language extends FabricLanguageProvider {
protected static void addBlock(TranslationBuilder translationBuilder, Block block, String value) {
translationBuilder.add(block, value);
//translationBuilder.add(block.asItem(), value);
translationBuilder.add(block.asItem(), value);
}
protected static void midnightconfig(TranslationBuilder translationBuilder, String key, String value) {
@@ -62,14 +62,12 @@ public abstract class Language extends FabricLanguageProvider {
public void createRepeatedTranslations(TranslationBuilder translationBuilder, String rockWord, String splitterWord, String stickWord) {
for (RockType type : RockType.values()) {
Block block = Registries.BLOCK.get(RocksMain.id(type.getName()));
String baseTranslation = langHelper.translate(Registries.BLOCK.get(Identifier.ofVanilla(type.name().toLowerCase())).getTranslationKey());
String baseTranslation = langHelper.translate(type.getStoneBlock().getTranslationKey());
addBlock(translationBuilder, block, baseTranslation+rockWord);
if (type != RockType.GRAVEL) {
Item splitter = Registries.ITEM.get(RocksMain.id(type.getSplitterName()));
String splitterBaseTranslation = langHelper.translate(type.getStoneBlock().getTranslationKey());
translationBuilder.add(splitter, splitterBaseTranslation+splitterWord);
translationBuilder.add(splitter, baseTranslation+splitterWord);
}
}
for (StickType type : StickType.values()) {
@@ -96,7 +94,7 @@ public abstract class Language extends FabricLanguageProvider {
public void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, TranslationBuilder translationBuilder) {
translationBuilder.add("itemGroup.rocks.rocks","This Rocks!");
createRepeatedTranslations(translationBuilder, " Rock", " Fragment", " Stick");
createRepeatedTranslations(translationBuilder, " Rock", " Splitter", " Stick");
addBlock(translationBuilder, RocksMain.Geyser, "Geyser");
addBlock(translationBuilder, RocksMain.NetherGeyser, "Nether Geyser");

View File

@@ -49,7 +49,7 @@ public class LootTables {
addDrop(block, this.dropsWithSilkTouch(block, ItemEntry.builder(alternative)));
}
public void addSilkTouchOrRareDrop(Block block, Item alternative, float... chances) {
RegistryWrapper.Impl<Enchantment> impl = this.registryLookup.getWrapperOrThrow(RegistryKeys.ENCHANTMENT);
RegistryWrapper.Impl<Enchantment> impl = this.registries.getOrThrow(RegistryKeys.ENCHANTMENT);
addDrop(block, this.dropsWithSilkTouch(block, ItemEntry.builder(alternative).conditionally(TableBonusLootCondition.builder(impl.getOrThrow(Enchantments.FORTUNE), chances))));
}
}

View File

@@ -0,0 +1,124 @@
package eu.midnightdust.motschen.rocks.datagen;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.blockstates.StarfishVariation;
import eu.midnightdust.motschen.rocks.util.RockType;
import eu.midnightdust.motschen.rocks.util.StickType;
import net.fabricmc.fabric.api.client.datagen.v1.provider.FabricModelProvider;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.minecraft.block.Block;
import net.minecraft.client.data.*;
import net.minecraft.client.render.item.model.ItemModel;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import java.util.*;
public class Models extends FabricModelProvider {
public static final TextureKey ZERO_TEXTURE_KEY = TextureKey.of("0");
public Models(FabricDataOutput output) {
super(output);
}
public static Identifier getBlockId(String s) {
return RocksMain.id("block/"+s);
}
public static Identifier getItemId(String s) {
return RocksMain.id("item/"+s);
}
public static Model getSimpleParentModel(Identifier parentId, String variant) {
return new Model(Optional.of(parentId), Optional.of(variant), ZERO_TEXTURE_KEY);
}
@Override
public void generateBlockStateModels(BlockStateModelGenerator bsModelGenerator) {
for (RockType type : RockType.values()) {
Block block = Registries.BLOCK.get(RocksMain.id(type.getName()));
RockModel.registerBlockModel(bsModelGenerator, block, type.getStoneBlock());
}
for (StickType type : StickType.values()) {
Block block = Registries.BLOCK.get(RocksMain.id(type.getName()+"_stick"));
StickModel.registerBlockModel(bsModelGenerator, block, type.getBaseBlock());
}
}
@Override
public void generateItemModels(ItemModelGenerator itemModelGenerator) {
for (RockType type : RockType.values()) {
Item item = Registries.ITEM.get(RocksMain.id(type.getName()));
registerParentedItemModel(itemModelGenerator, item, getItemId("rock_base"), type.getStoneBlock());
if (type != RockType.GRAVEL) {
Item splitter = Registries.ITEM.get(RocksMain.id(type.getSplitterName()));
registerParentedItemModel(itemModelGenerator, splitter, getItemId("splitter_base"), type.getStoneBlock());
}
}
for (StickType type : StickType.values()) {
Item item = Registries.ITEM.get(RocksMain.id(type.getName()+"_stick"));
registerParentedItemModel(itemModelGenerator, item, getItemId("stick_base"), type.getBaseBlock());
}
itemModelGenerator.register(RocksMain.Geyser.asItem());
itemModelGenerator.register(RocksMain.NetherGeyser.asItem());
registerStarfishItemVariations(itemModelGenerator, RocksMain.Starfish);
itemModelGenerator.register(RocksMain.Seashell.asItem());
itemModelGenerator.register(RocksMain.Pinecone.asItem());
}
public static void registerParentedItemModel(ItemModelGenerator modelGenerator, Item item, Identifier parentId, Block textureSource) {
TextureMap textureMap = TextureMap.of(ZERO_TEXTURE_KEY, TextureMap.getId(textureSource));
Identifier itemModel = getSimpleParentModel(parentId, "").upload(item, textureMap, modelGenerator.modelCollector);
modelGenerator.output.accept(item, ItemModels.basic(itemModel));
}
public final void registerStarfishItemVariations(ItemModelGenerator modelGenerator, Block starfish) {
Map<StarfishVariation, ItemModel.Unbaked> variantMap = new HashMap<>();
for (StarfishVariation variation : StarfishVariation.values()) {
variantMap.put(variation, ItemModels.basic(ModelIds.getBlockSubModelId(starfish, "_"+variation.toString())));
}
modelGenerator.output.accept(starfish.asItem(), ItemModels.select(RocksMain.STARFISH_VARIATION, ItemModels.basic(ModelIds.getItemModelId(starfish.asItem())), variantMap));
}
public static <T> List<BlockStateVariant> getRandomRotationVariants(VariantSetting<T> baseSettings, T value) {
List<BlockStateVariant> list = new ArrayList<>();
for (VariantSettings.Rotation rotation : VariantSettings.Rotation.values()) {
BlockStateVariant rotatedVariant = BlockStateVariant.create().put(baseSettings, value);
list.add(rotatedVariant.put(VariantSettings.Y, rotation));
}
return list;
}
private static class RockModel {
public static void registerBlockModel(BlockStateModelGenerator modelGenerator, Block rockBlock, Block textureSource) {
TextureMap textureMap = TextureMap.of(ZERO_TEXTURE_KEY, TextureMap.getId(textureSource));
Identifier largeRock = getSimpleParentModel(getBlockId("large_rock"), "_large").upload(rockBlock, textureMap, modelGenerator.modelCollector);
Identifier mediumRock = getSimpleParentModel(getBlockId("medium_rock"), "_medium").upload(rockBlock, textureMap, modelGenerator.modelCollector);
Identifier smallRock = getSimpleParentModel(getBlockId("small_rock"), "_small").upload(rockBlock, textureMap, modelGenerator.modelCollector);
Identifier tinyRock = getSimpleParentModel(getBlockId("tiny_rock"), "_tiny").upload(rockBlock, textureMap, modelGenerator.modelCollector);
modelGenerator.blockStateCollector.accept(createBlockState(rockBlock, new Identifier[]{largeRock, mediumRock, smallRock, tinyRock}));
}
private static BlockStateSupplier createBlockState(Block rockBlock, Identifier[] modelIds) {
return VariantsBlockStateSupplier.create(rockBlock)
.coordinate(BlockStateVariantMap.create(RocksMain.ROCK_VARIATION)
.registerVariants(variation -> getRandomRotationVariants(VariantSettings.MODEL, modelIds[3 - variation.ordinal()]))
);
}
}
private static class StickModel {
public static void registerBlockModel(BlockStateModelGenerator modelGenerator, Block stickBlock, Block textureSource) {
TextureMap textureMap = TextureMap.of(ZERO_TEXTURE_KEY, TextureMap.getId(textureSource));
Identifier largeRock = getSimpleParentModel(getBlockId("large_stick"), "_large").upload(stickBlock, textureMap, modelGenerator.modelCollector);
Identifier mediumRock = getSimpleParentModel(getBlockId("medium_stick"), "_medium").upload(stickBlock, textureMap, modelGenerator.modelCollector);
Identifier smallRock = getSimpleParentModel(getBlockId("small_stick"), "_small").upload(stickBlock, textureMap, modelGenerator.modelCollector);
modelGenerator.blockStateCollector.accept(createBlockState(stickBlock, new Identifier[]{largeRock, mediumRock, smallRock}));
}
private static BlockStateSupplier createBlockState(Block stickBlock, Identifier[] modelIds) {
return VariantsBlockStateSupplier.create(stickBlock)
.coordinate(BlockStateVariantMap.create(RocksMain.STICK_VARIATION)
.registerVariants(variation -> getRandomRotationVariants(VariantSettings.MODEL, modelIds[2 - variation.ordinal()]))
);
}
}
}

View File

@@ -3,10 +3,12 @@ package eu.midnightdust.motschen.rocks.datagen;
import eu.midnightdust.motschen.rocks.RocksMain;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.minecraft.data.server.recipe.RecipeExporter;
import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder;
import net.minecraft.data.recipe.RecipeExporter;
import net.minecraft.data.recipe.RecipeGenerator;
import net.minecraft.data.recipe.ShapelessRecipeJsonBuilder;
import net.minecraft.recipe.book.RecipeCategory;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.Identifier;
@@ -22,16 +24,31 @@ public class Recipes extends FabricRecipeProvider {
}
@Override
public void generate(RecipeExporter exporter) {
generateCrafting(exporter);
protected RecipeGenerator getRecipeGenerator(RegistryWrapper.WrapperLookup registries, RecipeExporter recipeExporter) {
return new RocksRecipeGenerator(registries, recipeExporter);
}
private void generateCrafting(RecipeExporter exporter) {
RocksMain.splittersByType.forEach(((rockType, splitter) -> {
ShapelessRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, rockType.getStoneBlock().asItem())
.input(splitter, 4)
.criterion(FabricRecipeProvider.hasItem(splitter), FabricRecipeProvider.conditionsFromItem(splitter))
.offerTo(exporter, rockType.name().toLowerCase()+"_from_splitter");
}));
public static class RocksRecipeGenerator extends RecipeGenerator {
protected RocksRecipeGenerator(RegistryWrapper.WrapperLookup registries, RecipeExporter exporter) {
super(registries, exporter);
}
@Override
public void generate() {
generateCrafting(exporter);
}
private void generateCrafting(RecipeExporter exporter) {
RocksMain.splittersByType.forEach(((rockType, splitter) -> {
ShapelessRecipeJsonBuilder.create(registries.getOrThrow(RegistryKeys.ITEM), RecipeCategory.BUILDING_BLOCKS, Registries.BLOCK.get(Identifier.ofVanilla(rockType.name().toLowerCase())).asItem())
.input(splitter, 4)
.criterion(RecipeGenerator.hasItem(splitter), this.conditionsFromItem(splitter))
.offerTo(exporter, rockType.name().toLowerCase()+"_from_splitter");
}));
}
}
}

View File

@@ -2,22 +2,22 @@ package eu.midnightdust.motschen.rocks.item.polymer;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.blockstates.StarfishVariation;
import eu.pb4.factorytools.api.item.AutoModeledPolymerItem;
import eu.pb4.polymer.core.api.block.PolymerBlock;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import eu.pb4.polymer.core.api.item.PolymerItem;
import eu.pb4.polymer.resourcepack.extras.api.ResourcePackExtras;
import net.minecraft.block.Block;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.packettweaker.PacketContext;
import static eu.midnightdust.motschen.rocks.util.polymer.PolyUtil.hasModOnClient;
import static eu.midnightdust.motschen.rocks.util.polymer.PolyUtil.polymerId;
public class StarfishItemPolymer extends BlockItem implements AutoModeledPolymerItem {
public class StarfishItemPolymer extends BlockItem implements PolymerItem {
private final Item polymerItem;
public <T extends Block & PolymerBlock> StarfishItemPolymer(T block, Settings settings, Item item) {
@@ -26,31 +26,22 @@ public class StarfishItemPolymer extends BlockItem implements AutoModeledPolymer
}
@Override
public Item getPolymerItem() {
return polymerItem;
}
@Override
public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
public @Nullable Identifier getPolymerItemModel(ItemStack itemStack, PacketContext context) {
var state = itemStack.getComponents().get(DataComponentTypes.BLOCK_STATE);
if (state != null && !state.isEmpty()) {
StarfishVariation variation = state.getValue(RocksMain.STARFISH_VARIATION);
if (variation != null) return MODELS.get(variation).value();
if (variation != null) return ResourcePackExtras.bridgeModel(polymerId("item/"+variation + "_starfish"));
}
return MODELS.get(this).value();
return itemStack.get(DataComponentTypes.ITEM_MODEL);
}
@Override
public void onRegistered(Identifier selfId) {
var item = Identifier.of(selfId.getNamespace(), "item/" + selfId.getPath());
MODELS.put(this, PolymerResourcePackUtils.requestModel(this.getPolymerItem(), item));
for (StarfishVariation variation : StarfishVariation.values()) {
MODELS.put(variation, PolymerResourcePackUtils.requestModel(this.getPolymerItem(), polymerId("item/" + variation.toString() + "_" + selfId.getPath())));
}
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
@Override
public boolean canSyncRawToClient(@Nullable ServerPlayerEntity player) {
return hasModOnClient(player);
public Item getPolymerItem(ItemStack itemStack, PacketContext packetContext) {
return polymerItem;
}
}
}

View File

@@ -9,7 +9,7 @@ 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,
ServerPlayNetworking.getSender(player).sendPacket(new ParticleS2CPacket((ParticleEffect) type, false, true, pos.x, pos.y, pos.z,
(float) offset.x / 16f, (float) offset.y / 16f, (float) offset.z / 16f, speed, 1));
}
}

View File

@@ -30,7 +30,7 @@ public class RegistryUtil {
}
public static Item blockItem(Block block, Identifier id) {
if (polymerMode) return PolyUtil.polymerBlockItem(block, id);
return new BlockItem(block, new Item.Settings());
return new BlockItem(block, new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id)));
}
public static Item registerItem(Identifier id, Item item) {
Registry.register(Registries.ITEM, id, item);

View File

@@ -12,7 +12,7 @@ import static eu.midnightdust.motschen.rocks.RocksMain.id;
public enum StickType {
OAK("oak", Blocks.OAK_LOG), SPRUCE("spruce", Blocks.SPRUCE_LOG), BIRCH("birch", Blocks.BIRCH_LOG),
JUNGLE("jungle", Blocks.JUNGLE_LOG), ACACIA("acacia", Blocks.ACACIA_LOG), DARK_OAK("dark_oak", Blocks.DARK_OAK_LOG),
CHERRY("cherry", Blocks.CHERRY_LOG), MANGROVE("mangrove", Blocks.MANGROVE_LOG),
CHERRY("cherry", Blocks.CHERRY_LOG), MANGROVE("mangrove", Blocks.MANGROVE_LOG), PALE_OAK("pale_oak", Blocks.PALE_OAK_LOG),
BAMBOO("bamboo", Blocks.BAMBOO_BLOCK), WARPED("warped", Blocks.WARPED_STEM), CRIMSON("crimson", Blocks.CRIMSON_STEM);

View File

@@ -17,6 +17,7 @@ import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
import eu.pb4.polymer.core.api.item.PolymerItemGroupUtils;
import eu.pb4.polymer.core.api.utils.PolymerSyncUtils;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import eu.pb4.polymer.resourcepack.extras.api.ResourcePackExtras;
import eu.pb4.polymer.virtualentity.api.ElementHolder;
import eu.pb4.polymer.virtualentity.api.attachment.BlockBoundAttachment;
import eu.pb4.polymer.virtualentity.impl.HolderHolder;
@@ -49,6 +50,10 @@ public class PolyUtil {
if (PASSABLE_WATERLOGGED_BLOCK == null) SMALL_BLOCK = Blocks.BARRIER.getDefaultState().with(WATERLOGGED, true);
PolymerResourcePackUtils.addModAssets(MOD_ID);
ResourcePackExtras.forDefault().addBridgedModelsFolder(id("block"), id("rocks"));
ResourcePackExtras.forDefault().addBridgedModelsFolder(polymerId("block"), polymerId("polymer-rocks"));
ResourcePackExtras.forDefault().addBridgedModelsFolder(polymerId("item"), polymerId("polymer-rocks"));
ItemDisplayNetherGeyserModel.initModels();
ItemDisplayOverworldGeyserModel.initModels();
ItemDisplayPineconeModel.initModels();
@@ -66,8 +71,8 @@ public class PolyUtil {
}
public static Item polymerBlockItem(Block block, Identifier id) {
if (block instanceof Starfish) return new StarfishItemPolymer((Block & PolymerBlock) block, new Item.Settings(), Items.KELP);
else return new FactoryBlockItem((Block & PolymerBlock) block, new Item.Settings(), Items.KELP);
if (block instanceof Starfish) return new StarfishItemPolymer((Block & PolymerBlock) block, new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id)), Items.KELP);
else return new FactoryBlockItem((Block & PolymerBlock) block, new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id)), Items.KELP);
}
public static Item simplePolymerItem(Identifier id) {

View File

@@ -69,6 +69,7 @@ public class FeatureInjector {
if (RocksConfig.jungleStick) BiomeModifications.addFeature(ctx -> isNotExcluded(ctx) && ctx.hasTag(BiomeTags.IS_JUNGLE), GenerationStep.Feature.TOP_LAYER_MODIFICATION, getKey("jungle_stick"));
if (RocksConfig.bambooStick) BiomeModifications.addFeature(ctx -> isNotExcluded(ctx) && ctx.hasTag(BiomeTags.IS_JUNGLE), GenerationStep.Feature.TOP_LAYER_MODIFICATION, getKey("bamboo_stick"));
if (RocksConfig.paleOakStick) BiomeModifications.addFeature(ctx -> isNotExcluded(ctx) && ctx.getBiomeKey().equals(BiomeKeys.PALE_GARDEN), GenerationStep.Feature.TOP_LAYER_MODIFICATION, getKey("pale_oak_stick"));
Predicate<BiomeSelectionContext> dark_oak_sticks = (ctx -> {
String name = ctx.getBiomeKey().getValue().toString();

View File

@@ -61,6 +61,7 @@ public class StickFeatures {
PlacedFeature STICK_PLACED_FEATURE = switch (type) {
case CRIMSON -> new PlacedFeature(RegistryEntry.of(CONFIGURED_FEATURES.get(type)), getNetherModifiers(90, 1, Blocks.CRIMSON_NYLIUM));
case WARPED -> new PlacedFeature(RegistryEntry.of(CONFIGURED_FEATURES.get(type)), getNetherModifiers(90, 1, Blocks.WARPED_NYLIUM));
case PALE_OAK -> new PlacedFeature(RegistryEntry.of(CONFIGURED_FEATURES.get(type)), getModifiers(20, 1, Blocks.GRASS_BLOCK, Blocks.PALE_MOSS_BLOCK));
case SPRUCE -> new PlacedFeature(RegistryEntry.of(CONFIGURED_FEATURES.get(type)), getModifiers(3, 1, Blocks.GRASS_BLOCK, Blocks.SNOW_BLOCK, Blocks.PODZOL));
default -> new PlacedFeature(RegistryEntry.of(CONFIGURED_FEATURES.get(type)), getModifiers(3, 1, Blocks.GRASS_BLOCK, Blocks.MUD, Blocks.PODZOL));
};