mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 06:11:24 +00:00
semi working fabric inventories
This commit is contained in:
@@ -62,6 +62,7 @@ public class LootTable {
|
|||||||
newStack.setAmount(1);
|
newStack.setAmount(1);
|
||||||
int slot = r.nextInt(i.getSize());
|
int slot = r.nextInt(i.getSize());
|
||||||
ItemStack slotItem = i.getItem(slot);
|
ItemStack slotItem = i.getItem(slot);
|
||||||
|
System.out.println("attempt: " + (slotItem == null ? null : slotItem.getHandle()));
|
||||||
if(slotItem == null) {
|
if(slotItem == null) {
|
||||||
i.setItem(slot, newStack);
|
i.setItem(slot, newStack);
|
||||||
stack.setAmount(stack.getAmount() - 1);
|
stack.setAmount(stack.getAmount() - 1);
|
||||||
|
|||||||
+1
@@ -25,5 +25,6 @@ public class BufferedLootApplication implements BufferedItem {
|
|||||||
}
|
}
|
||||||
Container container = (Container) data;
|
Container container = (Container) data;
|
||||||
table.fillInventory(container.getInventory(), new FastRandom(origin.hashCode()));
|
table.fillInventory(container.getInventory(), new FastRandom(origin.hashCode()));
|
||||||
|
data.update(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
|
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
|
||||||
|
|
||||||
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||||
GeneratorTypeAccessor.getValues().add(new GeneratorType("terra") {
|
GeneratorTypeAccessor.getVALUES().add(new GeneratorType("terra") {
|
||||||
@Override
|
@Override
|
||||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||||
ConfigPack pack = registry.get("DEFAULT");
|
ConfigPack pack = registry.get("DEFAULT");
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.dfsek.terra.fabric.inventory;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.platform.inventory.Inventory;
|
||||||
|
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||||
|
import com.dfsek.terra.fabric.world.FabricAdapter;
|
||||||
|
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
|
||||||
|
public class FabricInventory implements Inventory {
|
||||||
|
private final LootableContainerBlockEntity delegate;
|
||||||
|
|
||||||
|
public FabricInventory(LootableContainerBlockEntity delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public net.minecraft.inventory.Inventory getHandle() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return delegate.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem(int slot) {
|
||||||
|
net.minecraft.item.ItemStack itemStack = delegate.getStack(slot);
|
||||||
|
System.out.println("item @ " + slot + " GET: " + itemStack);
|
||||||
|
return itemStack.getItem() == Items.AIR ? null : FabricAdapter.adapt(itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItem(int slot, ItemStack newStack) {
|
||||||
|
System.out.println("item @ " + slot + ": " + newStack.getHandle());
|
||||||
|
delegate.setStack(slot, FabricAdapter.adapt(newStack));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.dfsek.terra.fabric.inventory;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.platform.inventory.Item;
|
||||||
|
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class FabricItem implements Item {
|
||||||
|
private final net.minecraft.item.Item delegate;
|
||||||
|
|
||||||
|
public FabricItem(net.minecraft.item.Item delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public net.minecraft.item.Item getHandle() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack newItemStack(int amount) {
|
||||||
|
return new FabricItemStack(new net.minecraft.item.ItemStack(delegate, amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getMaxDurability() {
|
||||||
|
return delegate.getMaxDamage();
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-1
@@ -3,6 +3,10 @@ package com.dfsek.terra.fabric.inventory;
|
|||||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||||
import com.dfsek.terra.api.platform.inventory.Item;
|
import com.dfsek.terra.api.platform.inventory.Item;
|
||||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||||
|
import com.dfsek.terra.fabric.world.FabricAdapter;
|
||||||
|
import com.mojang.brigadier.StringReader;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import net.minecraft.command.argument.ItemStackArgumentType;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -11,7 +15,11 @@ public class FabricItemHandle implements ItemHandle {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item createItem(String data) {
|
public Item createItem(String data) {
|
||||||
return null;
|
try {
|
||||||
|
return FabricAdapter.adapt(new ItemStackArgumentType().parse(new StringReader(data)).getItem());
|
||||||
|
} catch(CommandSyntaxException e) {
|
||||||
|
throw new IllegalArgumentException("Invalid item data \"" + data + "\"", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+14
-4
@@ -5,7 +5,11 @@ import com.dfsek.terra.api.platform.inventory.ItemStack;
|
|||||||
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
|
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
|
||||||
|
|
||||||
public class FabricItemStack implements ItemStack {
|
public class FabricItemStack implements ItemStack {
|
||||||
net.minecraft.item.ItemStack delegate;
|
private net.minecraft.item.ItemStack delegate;
|
||||||
|
|
||||||
|
public FabricItemStack(net.minecraft.item.ItemStack delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAmount() {
|
public int getAmount() {
|
||||||
@@ -19,12 +23,18 @@ public class FabricItemStack implements ItemStack {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item getType() {
|
public Item getType() {
|
||||||
return null;
|
return new FabricItem(delegate.getItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack clone() {
|
public ItemStack clone() {
|
||||||
return null;
|
try {
|
||||||
|
FabricItemStack stack = (FabricItemStack) super.clone();
|
||||||
|
stack.delegate = delegate;
|
||||||
|
return stack;
|
||||||
|
} catch(CloneNotSupportedException e) {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,7 +48,7 @@ public class FabricItemStack implements ItemStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getHandle() {
|
public net.minecraft.item.ItemStack getHandle() {
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -8,8 +8,8 @@ import java.util.List;
|
|||||||
|
|
||||||
@Mixin(GeneratorType.class)
|
@Mixin(GeneratorType.class)
|
||||||
public interface GeneratorTypeAccessor {
|
public interface GeneratorTypeAccessor {
|
||||||
@Accessor("VALUES")
|
@Accessor
|
||||||
static List<GeneratorType> getValues() {
|
static List<GeneratorType> getVALUES() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.dfsek.terra.fabric.world;
|
|||||||
import com.dfsek.terra.api.math.vector.Vector3;
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
import com.dfsek.terra.api.platform.block.BlockType;
|
import com.dfsek.terra.api.platform.block.BlockType;
|
||||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||||
|
import com.dfsek.terra.fabric.inventory.FabricItem;
|
||||||
|
import com.dfsek.terra.fabric.inventory.FabricItemStack;
|
||||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||||
import com.dfsek.terra.fabric.world.block.FabricBlockType;
|
import com.dfsek.terra.fabric.world.block.FabricBlockType;
|
||||||
import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing;
|
import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing;
|
||||||
@@ -14,6 +16,8 @@ import com.dfsek.terra.fabric.world.entity.FabricEntityType;
|
|||||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
|
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.state.property.Properties;
|
import net.minecraft.state.property.Properties;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.WorldAccess;
|
import net.minecraft.world.WorldAccess;
|
||||||
@@ -58,4 +62,15 @@ public final class FabricAdapter {
|
|||||||
return ((FabricEntityType) entityType).getHandle();
|
return ((FabricEntityType) entityType).getHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ItemStack adapt(com.dfsek.terra.api.platform.inventory.ItemStack itemStack) {
|
||||||
|
return ((FabricItemStack) itemStack).getHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static com.dfsek.terra.api.platform.inventory.ItemStack adapt(ItemStack itemStack) {
|
||||||
|
return new FabricItemStack(itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static com.dfsek.terra.api.platform.inventory.Item adapt(Item item) {
|
||||||
|
return new FabricItem(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -7,6 +7,7 @@ import com.dfsek.terra.fabric.world.FabricAdapter;
|
|||||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
|
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
|
||||||
|
import net.minecraft.block.AbstractChestBlock;
|
||||||
import net.minecraft.block.AbstractSignBlock;
|
import net.minecraft.block.AbstractSignBlock;
|
||||||
import net.minecraft.block.SpawnerBlock;
|
import net.minecraft.block.SpawnerBlock;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
@@ -33,6 +34,10 @@ public class FabricBlockState implements BlockState {
|
|||||||
} else if(block1 instanceof SpawnerBlock) {
|
} else if(block1 instanceof SpawnerBlock) {
|
||||||
MobSpawnerBlockEntity mobSpawnerBlockEntity = (MobSpawnerBlockEntity) worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector()));
|
MobSpawnerBlockEntity mobSpawnerBlockEntity = (MobSpawnerBlockEntity) worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector()));
|
||||||
return new FabricMobSpawner(mobSpawnerBlockEntity, worldAccess);
|
return new FabricMobSpawner(mobSpawnerBlockEntity, worldAccess);
|
||||||
|
} else if(block1 instanceof AbstractChestBlock) {
|
||||||
|
BlockEntity abstractChestBlock = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector()));
|
||||||
|
System.out.println("inventory: " + block1);
|
||||||
|
return new FabricContainer(abstractChestBlock, worldAccess);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -69,7 +74,7 @@ public class FabricBlockState implements BlockState {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update(boolean applyPhysics) {
|
public boolean update(boolean applyPhysics) {
|
||||||
(worldAccess).getChunk(blockEntity.getPos()).setBlockEntity(blockEntity.getPos(), blockEntity);
|
worldAccess.getChunk(blockEntity.getPos()).setBlockEntity(blockEntity.getPos(), blockEntity);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package com.dfsek.terra.fabric.world.block.state;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.platform.block.state.Container;
|
||||||
|
import com.dfsek.terra.api.platform.inventory.Inventory;
|
||||||
|
import com.dfsek.terra.fabric.inventory.FabricInventory;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||||
|
import net.minecraft.world.WorldAccess;
|
||||||
|
|
||||||
|
public class FabricContainer extends FabricBlockState implements Container {
|
||||||
|
public FabricContainer(BlockEntity blockEntity, WorldAccess worldAccess) {
|
||||||
|
super(blockEntity, worldAccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return new FabricInventory(((LootableContainerBlockEntity) blockEntity));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user