Port to 1.21.4 and more datagen

- Polymer mode is currently still broken
This commit is contained in:
Martin Prokoph
2024-12-30 22:32:35 +01:00
parent 75f9937035
commit f00ac39b79
365 changed files with 3364 additions and 1786 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

@@ -1,8 +1,6 @@
package eu.midnightdust.motschen.rocks;
import eu.midnightdust.motschen.rocks.datagen.LootTables;
import eu.midnightdust.motschen.rocks.datagen.Recipes;
import eu.midnightdust.motschen.rocks.datagen.Tags;
import eu.midnightdust.motschen.rocks.datagen.*;
import eu.midnightdust.motschen.rocks.world.configured_feature.MiscFeatures;
import eu.midnightdust.motschen.rocks.world.configured_feature.NetherFeatures;
import eu.midnightdust.motschen.rocks.world.configured_feature.RockFeatures;
@@ -25,7 +23,10 @@ public class RocksDataGen implements DataGeneratorEntrypoint {
pack.addProvider(LootTables.BlockLootTables::new);
pack.addProvider(Tags.Blocks::new);
pack.addProvider(Recipes::new);
System.out.println("out");
pack.addProvider(Language.English::new);
pack.addProvider(Language.German::new);
pack.addProvider(Models::new);
}
@Override
public String getEffectiveModId() {
@@ -34,7 +35,6 @@ public class RocksDataGen implements DataGeneratorEntrypoint {
@Override
public void buildRegistry(RegistryBuilder registryBuilder) {
System.out.println("building registry");
registryBuilder.addRegistry(RegistryKeys.CONFIGURED_FEATURE, RockFeatures::initConfigured);
registryBuilder.addRegistry(RegistryKeys.PLACED_FEATURE, RockFeatures::initPlaced);
registryBuilder.addRegistry(RegistryKeys.CONFIGURED_FEATURE, StickFeatures::initConfigured);
@@ -52,9 +52,8 @@ public class RocksDataGen implements DataGeneratorEntrypoint {
@Override
protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) {
System.out.println("configure");
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

@@ -54,6 +54,12 @@ public class RocksMain implements ModInitializer {
public static Map<WoodType, Stick> sticksByType = new HashMap<>();
public static Map<RockType, Item> splittersByType = new HashMap<>();
public static final Identifier PINECONE = id("pinecone");
public static final Identifier SEASHELL = id("seashell");
public static final Identifier STARFISH = id("starfish");
public static final Identifier GEYSER = id("geyser");
public static final Identifier NETHER_GEYSER = id("nether_geyser");
public static Block Pinecone;
public static Block Seashell;
public static Block Starfish;
@@ -66,7 +72,7 @@ public class RocksMain implements ModInitializer {
@Override
public void onInitialize() {
RocksConfig.init("rocks", RocksConfig.class);
RocksConfig.init(MOD_ID, RocksConfig.class);
if (polymerMode) polymerMode = RocksConfig.enablePolymerMode && !PlatformFunctions.isClientEnv();
PayloadTypeRegistry.playC2S().register(HelloPayload.PACKET_ID, HelloPayload.codec);
@@ -81,23 +87,24 @@ public class RocksMain implements ModInitializer {
if (polymerMode) PolyUtil.init();
for (RockType type : RockType.values()) {
rocksByType.put(type, registerBlockWithItem(id(type.getName()), polymerMode ? newRockPolymer() : new Rock()));
}
for (RockType type : RockType.values()) {
Identifier id = id(type.getName());
rocksByType.put(type, registerBlockWithItem(id, polymerMode ? newRockPolymer(id) : new Rock(id)));
if (type != RockType.GRAVEL)
splittersByType.put(type, registerItem(id(type.getSplitterName()), simpleItem()));
splittersByType.put(type, registerItem(id(type.getSplitterName()), simpleItem(id(type.getSplitterName()))));
}
for (WoodType type : WoodType.stream().toList()) {
sticksByType.put(type, registerBlockWithItem(id(type.name()+"_stick"), polymerMode ? newStickPolymer() : new Stick()));
Identifier id = id(type.name()+"_stick");
sticksByType.put(type, registerBlockWithItem(id, polymerMode ? newStickPolymer(id) : new Stick(id)));
}
Pinecone = registerBlockWithItem(Identifier.of(MOD_ID,"pinecone"), polymerMode ? newPineconePolymer() : new Pinecone());
Seashell = registerBlockWithItem(Identifier.of(MOD_ID,"seashell"), polymerMode ? newSeashellPolymer() : new Seashell());
Starfish = registerBlockWithItem(Identifier.of(MOD_ID,"starfish"), polymerMode ? newStarfishPolymer() : new Starfish());
Pinecone = registerBlockWithItem(PINECONE, polymerMode ? newPineconePolymer(PINECONE) : new Pinecone(PINECONE));
Seashell = registerBlockWithItem(SEASHELL, polymerMode ? newSeashellPolymer(SEASHELL) : new Seashell(SEASHELL));
Starfish = registerBlockWithItem(STARFISH, polymerMode ? newStarfishPolymer(STARFISH) : new Starfish(STARFISH));
Geyser = registerBlockWithItem(Identifier.of(MOD_ID,"geyser"), polymerMode ? newOverworldGeyserPolymer() : new OverworldGeyser());
NetherGeyser = registerBlockWithItem(Identifier.of(MOD_ID,"nether_geyser"), polymerMode ? newNetherGeyserPolymer() : new NetherGeyser());
Geyser = registerBlockWithItem(GEYSER, polymerMode ? newOverworldGeyserPolymer(GEYSER) : new OverworldGeyser(GEYSER));
NetherGeyser = registerBlockWithItem(NETHER_GEYSER, polymerMode ? newNetherGeyserPolymer(NETHER_GEYSER) : new NetherGeyser(NETHER_GEYSER));
registerItemGroup();
@@ -117,9 +124,9 @@ public class RocksMain implements ModInitializer {
PlatformFunctions.isModLoaded("factorytools");
}
public static Item simpleItem() {
if (polymerMode) return PolyUtil.simplePolymerItem();
return new Item(new Item.Settings());
public static Item simpleItem(Identifier id) {
if (polymerMode) return PolyUtil.simplePolymerItem(id);
return new Item(new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id)));
}
public static void registerItemGroup() {

View File

@@ -3,15 +3,17 @@ package eu.midnightdust.motschen.rocks.block;
import com.mojang.serialization.MapCodec;
import eu.midnightdust.motschen.rocks.block.blockentity.BlockEntityInit;
import eu.midnightdust.motschen.rocks.block.blockentity.NetherGeyserBlockEntity;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
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;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
@@ -27,8 +29,8 @@ public class NetherGeyser extends BlockWithEntity implements BlockEntityProvider
private static final VoxelShape SHAPE;
public static final BooleanProperty ACTIVE = BooleanProperty.of("active");
public NetherGeyser() {
super(AbstractBlock.Settings.copy(Blocks.STONE).strength(10).noCollision().dynamicBounds().nonOpaque().sounds(BlockSoundGroup.STONE));
public NetherGeyser(Identifier blockId) {
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));
}
@@ -67,6 +69,7 @@ public class NetherGeyser extends BlockWithEntity implements BlockEntityProvider
SHAPE = createCuboidShape(5, 0, 5, 11, 1, 11);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}

View File

@@ -3,16 +3,18 @@ package eu.midnightdust.motschen.rocks.block;
import com.mojang.serialization.MapCodec;
import eu.midnightdust.motschen.rocks.block.blockentity.BlockEntityInit;
import eu.midnightdust.motschen.rocks.block.blockentity.OverworldGeyserBlockEntity;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
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;
import net.minecraft.state.property.Properties;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
@@ -31,8 +33,8 @@ public class OverworldGeyser extends BlockWithEntity implements BlockEntityProvi
public static final BooleanProperty ACTIVE = BooleanProperty.of("active");
public static final BooleanProperty SNOWY = Properties.SNOWY;
public OverworldGeyser() {
super(AbstractBlock.Settings.copy(Blocks.STONE).strength(10).noCollision().dynamicBounds().nonOpaque().sounds(BlockSoundGroup.STONE));
public OverworldGeyser(Identifier blockId) {
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));
}
@@ -78,6 +80,7 @@ public class OverworldGeyser extends BlockWithEntity implements BlockEntityProvi
SNOWY_SHAPE = snowy;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}

View File

@@ -1,22 +1,25 @@
package eu.midnightdust.motschen.rocks.block;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
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() {
super(AbstractBlock.Settings.copy(Blocks.POPPY).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.WOOD));
public Pinecone(Identifier blockId) {
super(AbstractBlock.Settings.copy(Blocks.POPPY).registryKey(RegistryKey.of(RegistryKeys.BLOCK, blockId)).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.WOOD));
this.setDefaultState(this.stateManager.getDefaultState());
}
@@ -31,9 +34,12 @@ public class Pinecone extends Block {
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
@Override
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);
}
protected boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {return true;}
@Override
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;
@@ -27,8 +32,8 @@ public class Rock extends Block {
private static final VoxelShape SHAPE_LARGE;
private static final EnumProperty<RockVariation> ROCK_VARIATION = RocksMain.ROCK_VARIATION;
public Rock() {
super(AbstractBlock.Settings.copy(Blocks.POPPY).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.STONE));
public Rock(Identifier blockId) {
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));
}
@@ -59,12 +64,16 @@ public class Rock extends Block {
SHAPE_LARGE = createCuboidShape(0, 0, 0, 16, 3, 16);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
@Override
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);
}
protected boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {return true;}
@Override
protected boolean isTransparent(BlockState state) {return true;}
@Override
protected boolean canReplace(BlockState state, ItemPlacementContext context) {return true;}
}

View File

@@ -1,29 +1,30 @@
package eu.midnightdust.motschen.rocks.block;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.blockstates.RockVariation;
import eu.midnightdust.motschen.rocks.blockstates.SeashellVariation;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
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;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.Properties;
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;
@@ -33,8 +34,8 @@ public class Seashell extends Block implements Waterloggable {
private static final EnumProperty<SeashellVariation> SEASHELL_VARIATION = RocksMain.SEASHELL_VARIATION;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public Seashell() {
super(AbstractBlock.Settings.copy(Blocks.POPPY).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.STONE));
public Seashell(Identifier blockId) {
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));
}
@@ -72,11 +73,14 @@ public class Seashell extends Block implements Waterloggable {
SHAPE = createCuboidShape(0, 0, 0, 16, 3, 16);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
@Override
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

@@ -1,9 +1,7 @@
package eu.midnightdust.motschen.rocks.block;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.blockstates.RockVariation;
import eu.midnightdust.motschen.rocks.blockstates.StarfishVariation;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.component.ComponentMap;
import net.minecraft.component.DataComponentTypes;
@@ -13,25 +11,28 @@ 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;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.Properties;
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;
import static eu.midnightdust.motschen.rocks.RocksMain.STARFISH_VARIATION;
import static eu.midnightdust.motschen.rocks.RocksMain.id;
public class Starfish extends Block implements Waterloggable {
@@ -39,8 +40,8 @@ public class Starfish extends Block implements Waterloggable {
private static final EnumProperty<StarfishVariation> STARFISH_VARIATION = RocksMain.STARFISH_VARIATION;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public Starfish() {
super(AbstractBlock.Settings.copy(Blocks.POPPY).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.CORAL));
public Starfish(Identifier blockId) {
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));
}
@@ -57,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;
}
@@ -83,11 +84,14 @@ public class Starfish extends Block implements Waterloggable {
SHAPE = createCuboidShape(0, 0, 0, 16, 1, 16);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
@Override
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

@@ -1,27 +1,28 @@
package eu.midnightdust.motschen.rocks.block;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.blockstates.RockVariation;
import eu.midnightdust.motschen.rocks.blockstates.StickVariation;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
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;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.Properties;
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;
@@ -31,8 +32,8 @@ public class Stick extends Block {
private static final EnumProperty<StickVariation> STICK_VARIATION = RocksMain.STICK_VARIATION;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public Stick() {
super(AbstractBlock.Settings.copy(Blocks.POPPY).nonOpaque().dynamicBounds().sounds(BlockSoundGroup.WOOD));
public Stick(Identifier blockId) {
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));
}
@@ -63,12 +64,16 @@ public class Stick extends Block {
SHAPE = createCuboidShape(0, 0, 0, 16, 1, 16);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
@Override
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);
}
protected boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {return true;}
@Override
protected boolean isTransparent(BlockState state) {return true;}
@Override
protected boolean canReplace(BlockState state, ItemPlacementContext context) {return true;}
}

View File

@@ -2,6 +2,7 @@ package eu.midnightdust.motschen.rocks.block.blockentity;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.util.polymer.PolyUtil;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
@@ -14,8 +15,8 @@ public class BlockEntityInit {
public static BlockEntityType<NetherGeyserBlockEntity> NETHER_GEYSER_BE;
public static void init() {
OVERWORLD_GEYSER_BE = Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(RocksMain.MOD_ID,"overworld_geyser_blockentity"), BlockEntityType.Builder.create(OverworldGeyserBlockEntity::new, RocksMain.Geyser).build(null));
NETHER_GEYSER_BE = Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(RocksMain.MOD_ID,"nether_geyser_blockentity"), BlockEntityType.Builder.create(NetherGeyserBlockEntity::new, RocksMain.NetherGeyser).build(null));
OVERWORLD_GEYSER_BE = Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(RocksMain.MOD_ID,"overworld_geyser_blockentity"), FabricBlockEntityTypeBuilder.create(OverworldGeyserBlockEntity::new, RocksMain.Geyser).build());
NETHER_GEYSER_BE = Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(RocksMain.MOD_ID,"nether_geyser_blockentity"), FabricBlockEntityTypeBuilder.create(NetherGeyserBlockEntity::new, RocksMain.NetherGeyser).build());
if (polymerMode) PolyUtil.registerBlockEntities(OVERWORLD_GEYSER_BE, NETHER_GEYSER_BE);
}
}

View File

@@ -9,6 +9,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
@@ -30,10 +31,10 @@ public class NetherGeyserBlockEntity extends BlockEntity {
if (player != null) {
world.setBlockState(pos, state.with(NetherGeyser.ACTIVE, true));
if (RocksConfig.netherGeyserDamage) {
player.damage(world.getDamageSources().onFire(), 1);
if (RocksConfig.netherGeyserDamage && world instanceof ServerWorld serverWorld) {
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

@@ -11,24 +11,29 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
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;
public class NetherGeyserPolymer extends NetherGeyser implements PolymerBlock, PolymerTexturedBlock, BlockWithElementHolder {
@Override
public NetherGeyserPolymer(Identifier blockId) {
super(blockId);
}
public BlockState getPolymerBlockState(BlockState state) {
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
@@ -37,7 +42,6 @@ public class NetherGeyserPolymer extends NetherGeyser implements PolymerBlock, P
}
@Override
public boolean canSyncRawToClient(@Nullable ServerPlayerEntity player) {
return hasModOnClient(player);
}
public boolean canSyncRawToClient(PacketContext context) {return hasModOnClient(context.getPlayer());}
}

View File

@@ -11,24 +11,29 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
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;
public class OverworldGeyserPolymer extends OverworldGeyser implements PolymerBlock, PolymerTexturedBlock, BlockWithElementHolder {
@Override
public OverworldGeyserPolymer(Identifier blockId) {
super(blockId);
}
public BlockState getPolymerBlockState(BlockState state) {
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
@@ -37,7 +42,7 @@ public class OverworldGeyserPolymer extends OverworldGeyser implements PolymerBl
}
@Override
public boolean canSyncRawToClient(@Nullable ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -13,24 +13,29 @@ import net.minecraft.block.enums.BlockFace;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
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;
public class PineconePolymer extends Pinecone implements PolymerBlock, PolymerTexturedBlock, BlockWithElementHolder {
@Override
public PineconePolymer(Identifier blockId) {
super(blockId);
}
public BlockState getPolymerBlockState(BlockState state) {
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
@@ -39,7 +44,7 @@ public class PineconePolymer extends Pinecone implements PolymerBlock, PolymerTe
}
@Override
public boolean canSyncRawToClient(@Nullable ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -13,24 +13,29 @@ import net.minecraft.block.enums.BlockFace;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
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;
public class RockPolymer extends Rock implements PolymerBlock, PolymerTexturedBlock, BlockWithElementHolder {
@Override
public RockPolymer(Identifier blockId) {
super(blockId);
}
public BlockState getPolymerBlockState(BlockState state) {
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
@@ -39,7 +44,7 @@ public class RockPolymer extends Rock implements PolymerBlock, PolymerTexturedBl
}
@Override
public boolean canSyncRawToClient(@Nullable ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -11,25 +11,30 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
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;
public class SeashellPolymer extends Seashell implements PolymerBlock, PolymerTexturedBlock, BlockWithElementHolder {
@Override
public SeashellPolymer(Identifier blockId) {
super(blockId);
}
public BlockState getPolymerBlockState(BlockState state) {
if (state.get(WATERLOGGED)) return PolyUtil.PASSABLE_WATERLOGGED_BLOCK;
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
@@ -38,7 +43,7 @@ public class SeashellPolymer extends Seashell implements PolymerBlock, PolymerTe
}
@Override
public boolean canSyncRawToClient(@Nullable ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -11,25 +11,30 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
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;
public class StarfishPolymer extends Starfish implements PolymerBlock, PolymerTexturedBlock, BlockWithElementHolder {
@Override
public StarfishPolymer(Identifier blockId) {
super(blockId);
}
public BlockState getPolymerBlockState(BlockState state) {
if (state.get(WATERLOGGED)) return PolyUtil.PASSABLE_WATERLOGGED_BLOCK;
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
@@ -38,7 +43,7 @@ public class StarfishPolymer extends Starfish implements PolymerBlock, PolymerTe
}
@Override
public boolean canSyncRawToClient(@Nullable ServerPlayerEntity player) {
return hasModOnClient(player);
public boolean canSyncRawToClient(PacketContext context) {
return hasModOnClient(context.getPlayer());
}
}

View File

@@ -13,24 +13,29 @@ import net.minecraft.block.enums.BlockFace;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
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;
public class StickPolymer extends Stick implements PolymerBlock, PolymerTexturedBlock, BlockWithElementHolder {
@Override
public StickPolymer(Identifier blockId) {
super(blockId);
}
public BlockState getPolymerBlockState(BlockState state) {
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
@@ -39,7 +44,7 @@ public class StickPolymer extends Stick implements PolymerBlock, PolymerTextured
}
@Override
public boolean canSyncRawToClient(@Nullable 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) {

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,9 +24,9 @@ public class ItemDisplayStickModel extends ConditionalBlockModel {
public static void initModels() {
for (WoodType type : WoodType.stream().toList()) {
var stacks = new ItemStack[3];
stacks[0] = BaseItemProvider.requestModel(RocksMain.id("block/small_"+type.name()+"_stick"));
stacks[1] = BaseItemProvider.requestModel(RocksMain.id("block/medium_"+type.name()+"_stick"));
stacks[2] = BaseItemProvider.requestModel(RocksMain.id("block/large_"+type.name()+"_stick"));
stacks[0] = ItemDisplayElementUtil.getModel(RocksMain.id("block/small_"+type.name()+"_stick"));
stacks[1] = ItemDisplayElementUtil.getModel(RocksMain.id("block/medium_"+type.name()+"_stick"));
stacks[2] = ItemDisplayElementUtil.getModel(RocksMain.id("block/large_"+type.name()+"_stick"));
models.put(type, stacks);
}
}

View File

@@ -47,5 +47,5 @@ public class RocksConfig extends MidnightConfig {
@Entry(category = effects) public static boolean netherGeyserDamage = true;
@Entry(category = effects) public static boolean enablePolymerMode = true;
@Entry(category = effects, min = 0, max = 200, isSlider = true) public static int polymerViewDistance = 100;
@Entry(category = effects, requiredMod = "factorytools", min = 0, max = 200, isSlider = true) public static int polymerViewDistance = 100;
}

View File

@@ -0,0 +1,166 @@
package eu.midnightdust.motschen.rocks.datagen;
import eu.midnightdust.motschen.rocks.RocksMain;
import eu.midnightdust.motschen.rocks.util.RockType;
import eu.midnightdust.motschen.rocks.util.StickType;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider;
import net.minecraft.block.Block;
import net.minecraft.block.WoodType;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.Identifier;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
public abstract class Language extends FabricLanguageProvider {
LanguageHelper langHelper;
protected Language(FabricDataOutput dataOutput, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
super(dataOutput, registryLookup);
}
protected Language(FabricDataOutput dataOutput, String languageCode, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
super(dataOutput, languageCode, registryLookup);
}
public String getCommonString(String first, String second) {
// To get the pure wood set name, we compare the names of the log and plank blocks and only keep the common part
// Kinda cursed, but hey it works :)
StringBuilder commonTranslation = new StringBuilder();
for (String subFirst : first.split(" ")) {
for (String subSecond : second.split(" ")) {
String commonPart = "";
if (!second.contains(" ")) { // This is often the case in German
for (char c : subFirst.toCharArray()) {
String temp = commonPart + c;
if (subSecond.startsWith(temp)) commonPart = temp;
else break;
}
}
else if (subFirst.equals(subSecond)) commonPart = subSecond; // This is common in English
if (!commonPart.isEmpty()) {
commonTranslation.append(commonPart).append(" ");
break;
}
}
}
return commonTranslation.substring(0, commonTranslation.length()-1);
}
protected static void addBlock(TranslationBuilder translationBuilder, Block block, String value) {
translationBuilder.add(block, value);
translationBuilder.add(block.asItem(), value);
}
protected static void midnightconfig(TranslationBuilder translationBuilder, String key, String value) {
translationBuilder.add("rocks.midnightconfig."+key, value);
}
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(type.getStoneBlock().getTranslationKey());
addBlock(translationBuilder, block, baseTranslation+rockWord);
if (type != RockType.GRAVEL) {
Item splitter = Registries.ITEM.get(RocksMain.id(type.getSplitterName()));
translationBuilder.add(splitter, baseTranslation+splitterWord);
}
}
for (WoodType type : WoodType.stream().toList()) {
Block block = Registries.BLOCK.get(RocksMain.id(type.name()+"_stick"));
if (StickType.getBaseBlock(type) instanceof Block logBlock &&
Registries.BLOCK.get(Identifier.ofVanilla(type.name()+"_planks")) instanceof Block plankBlock &&
Registries.BLOCK.get(Identifier.ofVanilla(type.name()+"_stairs")) instanceof Block stairBlock) {
String logTranslation = langHelper.translate(logBlock.getTranslationKey());
String plankTranslation = langHelper.translate(plankBlock.getTranslationKey());
String stairTranslation = langHelper.translate(stairBlock.getTranslationKey());
addBlock(translationBuilder, block, getCommonString(getCommonString(logTranslation, plankTranslation), getCommonString(plankTranslation, stairTranslation)) + stickWord);
}
}
}
public static class English extends Language {
public English(FabricDataOutput dataOutput, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
super(dataOutput, registryLookup);
langHelper = new LanguageHelper("en_us");
}
@Override
public void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, TranslationBuilder translationBuilder) {
translationBuilder.add("itemGroup.rocks.rocks","This Rocks!");
createRepeatedTranslations(translationBuilder, " Rock", " Splitter", " Stick");
addBlock(translationBuilder, RocksMain.Geyser, "Geyser");
addBlock(translationBuilder, RocksMain.NetherGeyser, "Nether Geyser");
addBlock(translationBuilder, RocksMain.Starfish, "Starfish");
addBlock(translationBuilder, RocksMain.Seashell, "Seashell");
addBlock(translationBuilder, RocksMain.Pinecone, "Pinecone");
midnightconfig(translationBuilder, "title", "This Rocks! Config");
midnightconfig(translationBuilder, "category.rocks", "Rocks");
midnightconfig(translationBuilder, "category.sticks", "Sticks");
midnightconfig(translationBuilder, "category.misc", "Miscellaneous");
midnightconfig(translationBuilder, "category.effects", "Effects");
for (String key : Set.of("needs_restart", "needs_restart1", "needs_restart2")) {
midnightconfig(translationBuilder, key, "§cRestart the game after changing options here!");
}
midnightconfig(translationBuilder, "underwaterSeashell", "Underwater Seashell");
midnightconfig(translationBuilder, "underwaterStarfish", "Underwater Starfish");
midnightconfig(translationBuilder, "geyserLevitation", "Geyser Levitation");
midnightconfig(translationBuilder, "netherGeyserDamage", "Nether Geyser Damage");
midnightconfig(translationBuilder, "enablePolymerMode", "Enable Polymer Mode");
midnightconfig(translationBuilder, "enablePolymerMode.tooltip", "Allows the mod to work fully server-sided when used in combination with Polymer and FactoryTools");
midnightconfig(translationBuilder, "polymerViewDistance", "Polymer View Distance");
}
}
public static class German extends Language {
public German(FabricDataOutput dataOutput, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
super(dataOutput, "de_de", registryLookup);
langHelper = new LanguageHelper("de_de");
}
@Override
public void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, TranslationBuilder translationBuilder) {
translationBuilder.add("itemGroup.rocks.rocks","This Rocks!");
createRepeatedTranslations(translationBuilder, "brocken", "splitter", "stock");
addBlock(translationBuilder, RocksMain.Geyser, "Geysir");
addBlock(translationBuilder, RocksMain.NetherGeyser, "Nether-Geysir");
addBlock(translationBuilder, RocksMain.Starfish, "Seestern");
addBlock(translationBuilder, RocksMain.Seashell, "Muschel");
addBlock(translationBuilder, RocksMain.Pinecone, "Tannenzapfen");
midnightconfig(translationBuilder, "title", "This Rocks! Config");
midnightconfig(translationBuilder, "category.rocks", "Brocken");
midnightconfig(translationBuilder, "category.sticks", "Stöcke");
midnightconfig(translationBuilder, "category.misc", "Sonstiges");
midnightconfig(translationBuilder, "category.effects", "Effekte");
for (String key : Set.of("needs_restart", "needs_restart1", "needs_restart2")) {
midnightconfig(translationBuilder, key, "§cStarte das Spiel neu, nachdem du Änderungen vorgenommen hast!");
}
midnightconfig(translationBuilder, "underwaterSeashell", "Unterwasser-Muschel");
midnightconfig(translationBuilder, "underwaterStarfish", "Unterwasser-Seestern");
midnightconfig(translationBuilder, "geyserLevitation", "Geysir Schwebeeffekt");
midnightconfig(translationBuilder, "netherGeyserDamage", "Nether Geysir Schaden");
midnightconfig(translationBuilder, "enablePolymerMode", "Aktiviere Polymer-Modus");
midnightconfig(translationBuilder, "enablePolymerMode.tooltip", "Erlaubt der Mod, komplett serverseitig zu funktionieren, wenn Polymer und FactoryTools installiert sind");
midnightconfig(translationBuilder, "polymerViewDistance", "Polymer-Sichtweite");
}
}
}

View File

@@ -0,0 +1,29 @@
package eu.midnightdust.motschen.rocks.datagen;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import net.minecraft.client.MinecraftClient;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
public class LanguageHelper {
JsonObject language;
public LanguageHelper(String language) {
try {
var langFile = MinecraftClient.getInstance().getDefaultResourcePack().open(ResourceType.CLIENT_RESOURCES, Identifier.ofVanilla(String.format("lang/%s.json", language)));
if (langFile == null) throw new RuntimeException("Unable to load language "+language);
this.language = new Gson().fromJson(new InputStreamReader(langFile.get(), StandardCharsets.UTF_8), JsonObject.class);
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
public String translate(String translationKey) {
return language.get(translationKey).getAsString();
}
}

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,126 @@
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.block.WoodType;
import net.minecraft.client.data.*;
import net.minecraft.client.render.item.model.ItemModel;
import net.minecraft.client.render.item.model.SelectItemModel;
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 (WoodType type : WoodType.stream().toList()) {
Block block = Registries.BLOCK.get(RocksMain.id(type.name()+"_stick"));
StickModel.registerBlockModel(bsModelGenerator, block, StickType.getBaseBlock(type));
}
}
@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 (WoodType type : WoodType.stream().toList()) {
Item item = Registries.ITEM.get(RocksMain.id(type.name()+"_stick"));
registerParentedItemModel(itemModelGenerator, item, getItemId("stick_base"), StickType.getBaseBlock(type));
}
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;
@@ -17,17 +19,36 @@ public class Recipes extends FabricRecipeProvider {
super(output, registriesFuture);
}
@Override
public void generate(RecipeExporter exporter) {
generateCrafting(exporter);
public String getName() {
return "Recipes";
}
@Override
protected RecipeGenerator getRecipeGenerator(RegistryWrapper.WrapperLookup registries, RecipeExporter recipeExporter) {
return new RocksRecipeGenerator(registries, recipeExporter);
}
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(RecipeCategory.BUILDING_BLOCKS, Registries.BLOCK.get(Identifier.ofVanilla(rockType.name().toLowerCase())))
ShapelessRecipeJsonBuilder.create(registries.getOrThrow(RegistryKeys.ITEM), RecipeCategory.BUILDING_BLOCKS, Registries.BLOCK.get(Identifier.ofVanilla(rockType.name().toLowerCase())).asItem())
.input(splitter, 4)
.criterion(FabricRecipeProvider.hasItem(splitter), FabricRecipeProvider.conditionsFromItem(splitter))
.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(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

@@ -25,12 +25,12 @@ import static eu.midnightdust.motschen.rocks.RocksMain.polymerMode;
public class RegistryUtil {
public static <T extends Block> T registerBlockWithItem(Identifier id, T block) {
Registry.register(Registries.BLOCK, id, block);
registerItem(id, blockItem(block));
registerItem(id, blockItem(block, id));
return block;
}
public static Item blockItem(Block block) {
if (polymerMode) return PolyUtil.polymerBlockItem(block);
return new BlockItem(block, new Item.Settings());
public static Item blockItem(Block block, Identifier id) {
if (polymerMode) return PolyUtil.polymerBlockItem(block, id);
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

@@ -1,5 +1,7 @@
package eu.midnightdust.motschen.rocks.util;
import net.minecraft.block.Block;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import java.util.Arrays;
@@ -26,6 +28,12 @@ public enum RockType {
if (this.equals(RockType.STONE)) splitterName = "cobblestone_splitter";
return splitterName;
}
public Identifier getStoneId() {
return Identifier.ofVanilla(this.toString().toLowerCase());
}
public Block getStoneBlock() {
return Registries.BLOCK.get(getStoneId());
}
public Identifier[] getVariations() {
var variations = new Identifier[4];

View File

@@ -1,6 +1,10 @@
package eu.midnightdust.motschen.rocks.util;
import net.minecraft.block.Block;
import net.minecraft.block.WoodType;
import net.minecraft.registry.Registries;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import java.util.Objects;
@@ -10,4 +14,15 @@ public class StickType {
.replace("block.rocks.", "").replace("_stick", "")
)).findFirst().orElse(WoodType.OAK);
}
public static Block getBaseBlock(WoodType woodType) {
String logName = woodType.name() + "_";
if (woodType.soundType() == BlockSoundGroup.NETHER_WOOD) logName += "stem";
else if (woodType.soundType() == BlockSoundGroup.BAMBOO_WOOD) logName += "block";
else logName += "log";
if (Registries.BLOCK.containsId(Identifier.ofVanilla(logName))) {
return Registries.BLOCK.get(Identifier.ofVanilla(logName));
}
return null;
}
}

View File

@@ -9,12 +9,12 @@ import eu.midnightdust.motschen.rocks.block.polymer.model.*;
import eu.midnightdust.motschen.rocks.item.polymer.StarfishItemPolymer;
import eu.midnightdust.motschen.rocks.util.RockType;
import eu.pb4.factorytools.api.item.FactoryBlockItem;
import eu.pb4.factorytools.api.item.ModeledItem;
import eu.pb4.polymer.blocks.api.BlockModelType;
import eu.pb4.polymer.blocks.api.PolymerBlockResourceUtils;
import eu.pb4.polymer.core.api.block.PolymerBlock;
import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
import eu.pb4.polymer.core.api.item.PolymerItemGroupUtils;
import eu.pb4.polymer.core.api.item.SimplePolymerItem;
import eu.pb4.polymer.core.api.utils.PolymerSyncUtils;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import eu.pb4.polymer.virtualentity.api.ElementHolder;
@@ -27,6 +27,8 @@ import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
@@ -66,13 +68,14 @@ public class PolyUtil {
return playersWithMod.contains(player);
}
public static Item polymerBlockItem(Block block) {
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);
public static Item polymerBlockItem(Block block, Identifier id) {
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() {
return new ModeledItem(Items.FLINT, new Item.Settings());
public static Item simplePolymerItem(Identifier id) {
return new SimplePolymerItem(new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id)), Items.FLINT, true);
//return new ModeledItem(Items.FLINT, new Item.Settings());
}
public static void registerPolymerGroup() {
@@ -100,11 +103,11 @@ public class PolyUtil {
}
}
public static Rock newRockPolymer() {return new RockPolymer();}
public static Stick newStickPolymer() {return new StickPolymer();}
public static Block newPineconePolymer() {return new PineconePolymer();}
public static Block newSeashellPolymer() {return new SeashellPolymer();}
public static Block newStarfishPolymer() {return new StarfishPolymer();}
public static Block newOverworldGeyserPolymer() {return new OverworldGeyserPolymer();}
public static Block newNetherGeyserPolymer() {return new NetherGeyserPolymer();}
public static Rock newRockPolymer(Identifier id) {return new RockPolymer(id);}
public static Stick newStickPolymer(Identifier id) {return new StickPolymer(id);}
public static Block newPineconePolymer(Identifier id) {return new PineconePolymer(id);}
public static Block newSeashellPolymer(Identifier id) {return new SeashellPolymer(id);}
public static Block newStarfishPolymer(Identifier id) {return new StarfishPolymer(id);}
public static Block newOverworldGeyserPolymer(Identifier id) {return new OverworldGeyserPolymer(id);}
public static Block newNetherGeyserPolymer(Identifier id) {return new NetherGeyserPolymer(id);}
}