fix loads of bugs
This commit is contained in:
parent
8c83b2aaf3
commit
be29556850
8 changed files with 18 additions and 41 deletions
|
|
@ -6,7 +6,7 @@ minecraft_version=1.21.8
|
||||||
yarn_mappings=1.21.8+build.1
|
yarn_mappings=1.21.8+build.1
|
||||||
loader_version=0.17.2
|
loader_version=0.17.2
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=0.2
|
mod_version=0.3
|
||||||
maven_group=ovh.sad
|
maven_group=ovh.sad
|
||||||
archives_base_name=growglobe
|
archives_base_name=growglobe
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ public class GrowglobeClient implements ClientModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
BlockRenderLayerMap.putBlock(GrowGlobeBlocks.GROW_GLOBE_BLOCK, BlockRenderLayer.CUTOUT);
|
BlockRenderLayerMap.putBlock(GrowGlobeBlocks.GROW_GLOBE_BLOCK, BlockRenderLayer.CUTOUT);
|
||||||
GrowGlobeScreenHandlers.register();
|
|
||||||
HandledScreens.register(GrowGlobeScreenHandlers.GROW_GLOBE, GrowGlobeScreen::new);
|
HandledScreens.register(GrowGlobeScreenHandlers.GROW_GLOBE, GrowGlobeScreen::new);
|
||||||
BlockEntityRendererFactories.register(GrowGlobeBlockEntities.GROW_GLOBE, GrowGlobeBlockEntityRenderer::new);
|
BlockEntityRendererFactories.register(GrowGlobeBlockEntities.GROW_GLOBE, GrowGlobeBlockEntityRenderer::new);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,19 +34,14 @@ public class GrowGlobeBlock extends BlockWithEntity {
|
||||||
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
|
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
|
||||||
if (!world.isClient) {
|
if (!world.isClient) {
|
||||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||||
System.out.println("one");
|
|
||||||
|
|
||||||
if (blockEntity instanceof GrowGlobeBlockEntity screenHandlerFactory) {
|
if (blockEntity instanceof GrowGlobeBlockEntity screenHandlerFactory) {
|
||||||
System.out.println("two");
|
player.openHandledScreen(screenHandlerFactory);
|
||||||
if (player instanceof ServerPlayerEntity serverPlayer) {
|
|
||||||
System.out.println("three");
|
|
||||||
serverPlayer.openHandledScreen(screenHandlerFactory);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MapCodec<? extends BlockWithEntity> getCodec() {
|
protected MapCodec<? extends BlockWithEntity> getCodec() {
|
||||||
return CODEC;
|
return CODEC;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import net.minecraft.inventory.SidedInventory;
|
||||||
import net.minecraft.inventory.SimpleInventory;
|
import net.minecraft.inventory.SimpleInventory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
|
||||||
import net.minecraft.screen.ArrayPropertyDelegate;
|
import net.minecraft.screen.ArrayPropertyDelegate;
|
||||||
import net.minecraft.screen.PropertyDelegate;
|
import net.minecraft.screen.PropertyDelegate;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
import net.minecraft.screen.ScreenHandler;
|
||||||
|
|
@ -33,7 +32,7 @@ import java.util.List;
|
||||||
|
|
||||||
import static ovh.sad.growglobe.HarvestUtil.harvestBlock;
|
import static ovh.sad.growglobe.HarvestUtil.harvestBlock;
|
||||||
|
|
||||||
public class GrowGlobeBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory, SidedInventory {
|
public class GrowGlobeBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory<BlockPos>, SidedInventory {
|
||||||
public static final long CAPACITY = 10000;
|
public static final long CAPACITY = 10000;
|
||||||
public static final long MAX_INSERT = 200;
|
public static final long MAX_INSERT = 200;
|
||||||
public static final long MAX_EXTRACT = 0;
|
public static final long MAX_EXTRACT = 0;
|
||||||
|
|
@ -186,12 +185,10 @@ public class GrowGlobeBlockEntity extends BlockEntity implements ExtendedScreenH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getScreenOpeningData(ServerPlayerEntity player) {
|
public BlockPos getScreenOpeningData(ServerPlayerEntity player) {
|
||||||
return this.getPos();
|
return this.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// --- Inventory delegation ---
|
// --- Inventory delegation ---
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import net.minecraft.inventory.Inventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.screen.PropertyDelegate;
|
import net.minecraft.screen.PropertyDelegate;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
import net.minecraft.screen.ScreenHandler;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
import net.minecraft.screen.slot.Slot;
|
import net.minecraft.screen.slot.Slot;
|
||||||
|
|
||||||
public class GrowGlobeScreenHandler extends ScreenHandler {
|
public class GrowGlobeScreenHandler extends ScreenHandler {
|
||||||
|
|
@ -46,6 +47,11 @@ public class GrowGlobeScreenHandler extends ScreenHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScreenHandlerType<GrowGlobeScreenHandler> getType() {
|
||||||
|
return GrowGlobeScreenHandlers.GROW_GLOBE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack quickMove(PlayerEntity player, int index) {
|
public ItemStack quickMove(PlayerEntity player, int index) {
|
||||||
ItemStack newStack = ItemStack.EMPTY;
|
ItemStack newStack = ItemStack.EMPTY;
|
||||||
|
|
@ -99,7 +105,7 @@ public class GrowGlobeScreenHandler extends ScreenHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUse(PlayerEntity player) {
|
public boolean canUse(PlayerEntity player) {
|
||||||
return inventory.canPlayerUse(player);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEnergy() {
|
public int getEnergy() {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import net.minecraft.screen.ScreenHandlerType;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
// ModScreenHandlers.java
|
|
||||||
public class GrowGlobeScreenHandlers {
|
public class GrowGlobeScreenHandlers {
|
||||||
public static ScreenHandlerType<GrowGlobeScreenHandler> GROW_GLOBE;
|
public static ScreenHandlerType<GrowGlobeScreenHandler> GROW_GLOBE;
|
||||||
|
|
||||||
|
|
@ -16,18 +15,15 @@ public class GrowGlobeScreenHandlers {
|
||||||
Registries.SCREEN_HANDLER,
|
Registries.SCREEN_HANDLER,
|
||||||
Identifier.of(Growglobe.MOD_ID, "growglobe"),
|
Identifier.of(Growglobe.MOD_ID, "growglobe"),
|
||||||
new ExtendedScreenHandlerType<>(
|
new ExtendedScreenHandlerType<>(
|
||||||
// Decoder: called on client
|
(syncId, playerInv, pos) -> {
|
||||||
(syncId, playerInv, buf) -> {
|
|
||||||
BlockPos pos = buf;
|
|
||||||
|
|
||||||
var be = playerInv.player.getWorld().getBlockEntity(pos);
|
var be = playerInv.player.getWorld().getBlockEntity(pos);
|
||||||
|
|
||||||
if (be instanceof GrowGlobeBlockEntity blockEntity) {
|
if (be instanceof GrowGlobeBlockEntity blockEntity) {
|
||||||
return new GrowGlobeScreenHandler(syncId, playerInv, blockEntity.getInventory(), blockEntity.getPropertyDelegate());
|
return new GrowGlobeScreenHandler(syncId, playerInv, blockEntity.getInventory(), blockEntity.getPropertyDelegate());
|
||||||
}
|
}
|
||||||
// Fallback if BE missing
|
|
||||||
return new GrowGlobeScreenHandler(syncId, playerInv, new net.minecraft.inventory.SimpleInventory(7), new net.minecraft.screen.ArrayPropertyDelegate(2));
|
return new GrowGlobeScreenHandler(syncId, playerInv, new net.minecraft.inventory.SimpleInventory(7), new net.minecraft.screen.ArrayPropertyDelegate(2));
|
||||||
},
|
},
|
||||||
// PacketCodec to sync BlockPos
|
|
||||||
BlockPos.PACKET_CODEC
|
BlockPos.PACKET_CODEC
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package ovh.sad.growglobe;
|
package ovh.sad.growglobe;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class Growglobe implements ModInitializer {
|
public class Growglobe implements ModInitializer {
|
||||||
public static String MOD_ID = "growglobe";
|
public static String MOD_ID = "growglobe";
|
||||||
|
|
@ -9,6 +8,7 @@ public class Growglobe implements ModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
GrowGlobeBlocks.initialize();
|
GrowGlobeBlocks.initialize();
|
||||||
|
GrowGlobeScreenHandlers.register();
|
||||||
GrowGlobeBlockEntities.register();
|
GrowGlobeBlockEntities.register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,33 +4,19 @@ import net.minecraft.block.*;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.registry.Registries;
|
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.registry.RegistryKeys;
|
||||||
import net.minecraft.registry.entry.RegistryEntry;
|
|
||||||
import net.minecraft.registry.tag.BlockTags;
|
import net.minecraft.registry.tag.BlockTags;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||||
import net.minecraft.world.gen.feature.TreeFeatureConfig;
|
import net.minecraft.world.gen.feature.TreeFeatureConfig;
|
||||||
import net.minecraft.world.gen.foliage.SpruceFoliagePlacer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class HarvestUtil {
|
public class HarvestUtil {
|
||||||
|
|
||||||
/**
|
|
||||||
* Dynamically harvests any block or item and returns the resulting drops.
|
|
||||||
* Works with vanilla and modded blocks.
|
|
||||||
*
|
|
||||||
* @param world the world
|
|
||||||
* @param item the Item (usually BlockItem) to harvest
|
|
||||||
* @param pos the position (optional for context; can be BlockPos.ORIGIN)
|
|
||||||
* @return List of ItemStacks that would drop
|
|
||||||
*/
|
|
||||||
public static List<ItemStack> harvestBlock(ServerWorld world, Item item, BlockPos pos) {
|
public static List<ItemStack> harvestBlock(ServerWorld world, Item item, BlockPos pos) {
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -41,13 +27,11 @@ public class HarvestUtil {
|
||||||
|
|
||||||
BlockEntityProvider blockEntityProvider = block instanceof BlockEntityProvider bep ? bep : null;
|
BlockEntityProvider blockEntityProvider = block instanceof BlockEntityProvider bep ? bep : null;
|
||||||
|
|
||||||
// CropBlock: drop crop + seeds
|
|
||||||
if (block instanceof CropBlock crop) {
|
if (block instanceof CropBlock crop) {
|
||||||
state = crop.withAge(crop.getMaxAge());
|
state = crop.withAge(crop.getMaxAge());
|
||||||
}
|
}
|
||||||
// Stackable plants like sugar cane or bamboo
|
|
||||||
else if (block instanceof SugarCaneBlock) {
|
else if (block instanceof SugarCaneBlock) {
|
||||||
int height = 3; // or dynamically detect in world
|
int height = 3;
|
||||||
for (int i = 0; i < height; i++) drops.add(new ItemStack(block));
|
for (int i = 0; i < height; i++) drops.add(new ItemStack(block));
|
||||||
return drops;
|
return drops;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue