1.3.6.1
Adds in item scrubber Fixes vault item highlight issue with new vault GUI Begin adding some functions from Tinkers Construct, as well as assets. Add a nether resource dimension
This commit is contained in:
parent
f3bce6751b
commit
2a3fec5d66
140 changed files with 2984 additions and 215 deletions
|
@ -40,6 +40,7 @@ import org.slf4j.Logger;
|
|||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.otemod.blocks.ModBlocks;
|
||||
import dev.zontreck.otemod.blocks.entity.ModEntities;
|
||||
import dev.zontreck.otemod.chat.ChatServerOverride;
|
||||
import dev.zontreck.otemod.commands.CommandRegistry;
|
||||
import dev.zontreck.otemod.commands.teleport.TeleportContainer;
|
||||
|
@ -48,9 +49,10 @@ import dev.zontreck.otemod.configs.Profile;
|
|||
import dev.zontreck.otemod.database.Database;
|
||||
import dev.zontreck.otemod.database.Database.DatabaseConnectionException;
|
||||
import dev.zontreck.otemod.events.EventHandler;
|
||||
import dev.zontreck.otemod.implementation.VaultScreen;
|
||||
import dev.zontreck.otemod.implementation.VaultWatcher;
|
||||
import dev.zontreck.otemod.implementation.inits.MenuInitializer;
|
||||
import dev.zontreck.otemod.implementation.inits.ModMenuTypes;
|
||||
import dev.zontreck.otemod.implementation.scrubber.ScrubberScreen;
|
||||
import dev.zontreck.otemod.implementation.vault.VaultScreen;
|
||||
import dev.zontreck.otemod.implementation.vault.VaultWatcher;
|
||||
import dev.zontreck.otemod.items.ModItems;
|
||||
import dev.zontreck.otemod.ore.Modifier.ModifierOfBiomes;
|
||||
|
||||
|
@ -106,10 +108,12 @@ public class OTEMod
|
|||
MinecraftForge.EVENT_BUS.register(new CommandRegistry());
|
||||
MinecraftForge.EVENT_BUS.register(new VaultWatcher());
|
||||
MinecraftForge.EVENT_BUS.register(new dev.zontreck.otemod.zschem.EventHandler());
|
||||
MenuInitializer.CONTAINERS.register(bus);
|
||||
ModMenuTypes.CONTAINERS.register(bus);
|
||||
|
||||
ModBlocks.register(bus);
|
||||
ModItems.register(bus);
|
||||
ModEntities.register(bus);
|
||||
//MenuInitializer.register(bus);
|
||||
}
|
||||
|
||||
private void setup(final FMLCommonSetupEvent event)
|
||||
|
@ -279,7 +283,8 @@ public class OTEMod
|
|||
//LOGGER.info("HELLO FROM CLIENT SETUP");
|
||||
//LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
|
||||
|
||||
MenuScreens.register(MenuInitializer.VAULT.get(), VaultScreen::new);
|
||||
MenuScreens.register(ModMenuTypes.VAULT.get(), VaultScreen::new);
|
||||
MenuScreens.register(ModMenuTypes.SCRUBBER.get(), ScrubberScreen::new);
|
||||
|
||||
//ItemBlockRenderTypes.setRenderLayer(ModBlocks.AURORA_DOOR.get(), RenderType.translucent());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package dev.zontreck.otemod.blocks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import dev.zontreck.otemod.blocks.entity.ItemScrubberBlockEntity;
|
||||
import dev.zontreck.otemod.blocks.entity.ModEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
public class ItemScrubberBlock extends BaseEntityBlock
|
||||
{
|
||||
|
||||
public ItemScrubberBlock(Properties p_54120_) {
|
||||
super(p_54120_);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RenderShape getRenderShape(BlockState state)
|
||||
{
|
||||
return RenderShape.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level lvl, BlockPos pos, BlockState newState, boolean isMoving)
|
||||
{
|
||||
if(state.getBlock()!=newState.getBlock())
|
||||
{
|
||||
BlockEntity bE = lvl.getBlockEntity(pos);
|
||||
if(bE instanceof ItemScrubberBlockEntity)
|
||||
{
|
||||
((ItemScrubberBlockEntity)bE).doDrop();
|
||||
}
|
||||
}
|
||||
|
||||
super.onRemove(state, lvl, pos, newState, isMoving);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState state, Level lvl, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit)
|
||||
{
|
||||
if(!lvl.isClientSide())
|
||||
{
|
||||
BlockEntity be = lvl.getBlockEntity(pos);
|
||||
if(be instanceof ItemScrubberBlockEntity)
|
||||
{
|
||||
NetworkHooks.openScreen(((ServerPlayer)player), (ItemScrubberBlockEntity)be, pos);
|
||||
}else{
|
||||
throw new IllegalStateException("Our container is missing!");
|
||||
}
|
||||
}
|
||||
|
||||
return InteractionResult.sidedSuccess(lvl.isClientSide);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new ItemScrubberBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level lvl, BlockState state, BlockEntityType<T> type)
|
||||
{
|
||||
return createTickerHelper(type, ModEntities.ITEM_SCRUBBER.get(), ItemScrubberBlockEntity::tick);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +1,22 @@
|
|||
package dev.zontreck.otemod.blocks;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.DoorBlock;
|
||||
import net.minecraft.world.level.block.IronBarsBlock;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour.StatePredicate;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.material.MaterialColor;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
@ -25,10 +32,42 @@ public class ModBlocks {
|
|||
OTEMod.LOGGER.info("Registering all blocks...");
|
||||
}
|
||||
|
||||
public static final RegistryObject<Block> ETERNIUM_ORE_BLOCK = BLOCKS.register("eternium_ore_block", () -> new Block(BlockBehaviour.Properties.of(Material.METAL).requiresCorrectToolForDrops().strength(4f).explosionResistance(1200).destroyTime(6)));
|
||||
public static final RegistryObject<Block> ETERNIUM_ORE_BLOCK = BLOCKS.register("eternium_ore_block", () -> new Block(BlockBehaviour.Properties.of(Material.METAL).requiresCorrectToolForDrops().strength(7F).explosionResistance(1200).destroyTime(6)));
|
||||
|
||||
public static final RegistryObject<Item> ETERNIUM_ORE_BLOCK_I = ITEMS.register("eternium_ore_block", () -> new BlockItem(ETERNIUM_ORE_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
|
||||
//#region TINKERS BLOCKS
|
||||
|
||||
public static final RegistryObject<Block> COBALT_ORE_BLOCK = BLOCKS.register("cobalt_ore", () -> new Block(BlockBehaviour.Properties.of(Material.STONE, MaterialColor.NETHER).sound(SoundType.NETHER_ORE).requiresCorrectToolForDrops().strength(10.0F)));
|
||||
|
||||
public static final RegistryObject<Item> COBALT_ORE_ITEM = ITEMS.register("cobalt_ore", ()->new BlockItem(COBALT_ORE_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS)));
|
||||
|
||||
public static final RegistryObject<Block> RAW_COBALT_ORE_BLOCK = BLOCKS.register("raw_cobalt_ore", () -> new Block(BlockBehaviour.Properties.of(Material.STONE, MaterialColor.COLOR_BLUE).sound(SoundType.NETHER_ORE).requiresCorrectToolForDrops().strength(6.0F, 7.0F)));
|
||||
|
||||
public static final RegistryObject<Item> RAW_COBALT_ORE_ITEM = ITEMS.register("raw_cobalt_ore", ()->new BlockItem(RAW_COBALT_ORE_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS)));
|
||||
|
||||
public static final RegistryObject<Block> GOLD_BARS = BLOCKS.register("gold_bars", ()-> new IronBarsBlock(BlockBehaviour.Properties.of(Material.METAL, MaterialColor.NONE).requiresCorrectToolForDrops().strength(3.0F, 6.0F).sound(SoundType.METAL).noOcclusion()));
|
||||
|
||||
public static final RegistryObject<Item> GOLD_BARS_I = ITEMS.register("gold_bars", ()-> new BlockItem(GOLD_BARS.get(), new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS)));
|
||||
|
||||
public static final RegistryObject<Block> COBALT_BLOCK = BLOCKS.register("cobalt_block", ()-> new Block(BlockBehaviour.Properties.of(Material.METAL, MaterialColor.COLOR_BLUE).requiresCorrectToolForDrops().strength(3.0F, 6.0F).sound(SoundType.METAL)));
|
||||
|
||||
public static final RegistryObject<Item> COBALT_BLOCK_I = ITEMS.register("cobalt_block", ()-> new BlockItem(COBALT_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS)));
|
||||
|
||||
public static final RegistryObject<Block> NETHER_GROUT = BLOCKS.register("nether_grout", ()-> new Block(BlockBehaviour.Properties.of(Material.SAND, MaterialColor.NONE).strength(3.0F).friction(0.8F).sound(SoundType.SOUL_SOIL)));
|
||||
|
||||
public static final RegistryObject<Item> NETHER_GROUT_I = ITEMS.register("nether_grout", ()-> new BlockItem(NETHER_GROUT.get(), new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS)));
|
||||
|
||||
public static final BlockBehaviour.Properties SCORCHED_BASE = BlockBehaviour.Properties.of(Material.STONE, MaterialColor.TERRACOTTA_BROWN).requiresCorrectToolForDrops().strength(2.5F, 8.0F);
|
||||
public static final BlockBehaviour.Properties SCORCHED_BASE_NONSOLID = SCORCHED_BASE.noOcclusion();
|
||||
|
||||
public static final RegistryObject<Block> SCORCHED_TABLE = BLOCKS.register("scorched_table", ()-> new Block(SCORCHED_BASE_NONSOLID));
|
||||
|
||||
public static final RegistryObject<Item> SCORCHED_TABLE_I = ITEMS.register("scorched_table", ()-> new BlockItem(SCORCHED_TABLE.get(), new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS)));
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
public static final RegistryObject<Block> DEEPSLATE_ETERNIUM_ORE_BLOCK = BLOCKS.register("deepslate_eternium_ore_block", () -> new Block(BlockBehaviour.Properties.of(Material.METAL).requiresCorrectToolForDrops().strength(5f).explosionResistance(1200).destroyTime(7)));
|
||||
|
||||
public static final RegistryObject<Item> DEEPSLATE_ETERNIUM_ORE_BLOCK_I = ITEMS.register("deepslate_eternium_ore_block", () -> new BlockItem(DEEPSLATE_ETERNIUM_ORE_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
|
@ -43,8 +82,18 @@ public class ModBlocks {
|
|||
public static final RegistryObject<Item> AURORA_DOOR_I = ITEMS.register("aurora_door", () -> new BlockItem(AURORA_DOOR.get(), new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
|
||||
|
||||
public static final RegistryObject<Block> CLEAR_GLASS_BLOCK = BLOCKS.register("clear_glass_block", () -> new Block(BlockBehaviour.Properties.copy(Blocks.GLASS).strength(1f).destroyTime(6)));
|
||||
public static final RegistryObject<Block> CLEAR_GLASS_BLOCK = BLOCKS.register("clear_glass_block", () -> new Block(BlockBehaviour.Properties.copy(Blocks.GLASS).strength(1f).destroyTime(6).noOcclusion().isViewBlocking(ModBlocks::never)));
|
||||
|
||||
public static final RegistryObject<Item> CLEAR_GLASS_BLOCK_I = ITEMS.register("clear_glass_block", () -> new BlockItem(CLEAR_GLASS_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
|
||||
|
||||
public static final RegistryObject<Block> ITEM_SCRUBBER = BLOCKS.register("item_scrubber", ()->new ItemScrubberBlock(BlockBehaviour.Properties.copy(ModBlocks.AURORA_BLOCK.get()).noOcclusion().isViewBlocking(ModBlocks::never)));
|
||||
|
||||
public static final RegistryObject<Item> ITEM_SCRUBBER_I = ITEMS.register("item_scrubber", ()->new BlockItem(ITEM_SCRUBBER.get(), new Item.Properties().tab(CreativeModeTab.TAB_REDSTONE)));
|
||||
|
||||
|
||||
|
||||
private static boolean never(BlockState p_50806_, BlockGetter p_50807_, BlockPos p_50808_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,247 @@
|
|||
package dev.zontreck.otemod.blocks.entity;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import dev.zontreck.otemod.implementation.OutputItemStackHandler;
|
||||
import dev.zontreck.otemod.implementation.scrubber.ScrubberMenu;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.Containers;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class ItemScrubberBlockEntity extends BlockEntity implements MenuProvider
|
||||
{
|
||||
|
||||
protected final ItemStackHandler itemsHandler = new ItemStackHandler(1){
|
||||
@Override
|
||||
protected void onContentsChanged(int slot)
|
||||
{
|
||||
setChanged();
|
||||
}
|
||||
};
|
||||
protected final ItemStackHandler outputItems = new ItemStackHandler(1){
|
||||
@Override
|
||||
protected void onContentsChanged(int slot)
|
||||
{
|
||||
setChanged();
|
||||
}
|
||||
};
|
||||
private ItemStackHandler outputSlot;
|
||||
|
||||
private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty();
|
||||
private LazyOptional<IItemHandler> lazyOutputItems = LazyOptional.empty();
|
||||
|
||||
public ItemScrubberBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(ModEntities.ITEM_SCRUBBER.get(), pos, state);
|
||||
outputSlot = new OutputItemStackHandler(outputItems);
|
||||
|
||||
this.data = new ContainerData() {
|
||||
|
||||
@Override
|
||||
public int get(int p_39284_) {
|
||||
return switch(p_39284_){
|
||||
case 0 -> ItemScrubberBlockEntity.this.progress;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int p_39285_, int p_39286_) {
|
||||
switch(p_39285_)
|
||||
{
|
||||
case 0 -> ItemScrubberBlockEntity.this.progress = p_39286_;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
protected final ContainerData data;
|
||||
private int progress = 0;
|
||||
|
||||
public static final int MAXIMUM_PROCESSING_TICKS = 750;
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public AbstractContainerMenu createMenu(int id, Inventory inv, Player player) {
|
||||
return new ScrubberMenu(id, inv, this, this.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
return Component.translatable("block.otemod.item_scrubber");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side)
|
||||
{
|
||||
if(side == Direction.DOWN && cap == ForgeCapabilities.ITEM_HANDLER)
|
||||
{
|
||||
// Return the output slot only
|
||||
return lazyOutputItems.cast();
|
||||
}
|
||||
if(cap == ForgeCapabilities.ITEM_HANDLER)
|
||||
{
|
||||
return lazyItemHandler.cast();
|
||||
}
|
||||
|
||||
return super.getCapability(cap,side);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
super.onLoad();
|
||||
lazyItemHandler = LazyOptional.of(()->itemsHandler);
|
||||
lazyOutputItems = LazyOptional.of(()->outputSlot);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void invalidateCaps()
|
||||
{
|
||||
super.invalidateCaps();
|
||||
lazyItemHandler.invalidate();
|
||||
lazyOutputItems.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag nbt)
|
||||
{
|
||||
nbt.put("inventory", itemsHandler.serializeNBT());
|
||||
nbt.put("output", outputItems.serializeNBT());
|
||||
nbt.putInt("prog", progress);
|
||||
|
||||
super.saveAdditional(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag nbt){
|
||||
super.load(nbt);
|
||||
|
||||
itemsHandler.deserializeNBT(nbt.getCompound("inventory"));
|
||||
outputItems.deserializeNBT(nbt.getCompound("output"));
|
||||
progress = nbt.getInt("prog");
|
||||
}
|
||||
|
||||
public void doDrop()
|
||||
{
|
||||
SimpleContainer cont = new SimpleContainer(itemsHandler.getSlots());
|
||||
for (int i = 0; i < itemsHandler.getSlots(); i++) {
|
||||
cont.setItem(i, itemsHandler.getStackInSlot(i));
|
||||
}
|
||||
cont = new SimpleContainer(outputItems.getSlots());
|
||||
for (int i = 0; i < outputItems.getSlots(); i++) {
|
||||
cont.setItem(i, outputItems.getStackInSlot(i));
|
||||
}
|
||||
|
||||
Containers.dropContents(this.level, this.worldPosition, cont);
|
||||
}
|
||||
|
||||
public static void tick(Level lvl, BlockPos pos, BlockState state, ItemScrubberBlockEntity entity)
|
||||
{
|
||||
if(lvl.isClientSide())return;
|
||||
|
||||
if(hasRecipe(entity))
|
||||
{
|
||||
entity.progress++;
|
||||
setChanged(lvl, pos, state);
|
||||
|
||||
if(entity.progress >= ItemScrubberBlockEntity.MAXIMUM_PROCESSING_TICKS)
|
||||
{
|
||||
craftItem(entity);
|
||||
}
|
||||
}else {
|
||||
if(entity.progress>0){
|
||||
entity.resetProgress();
|
||||
setChanged(lvl, pos, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void craftItem(ItemScrubberBlockEntity entity) {
|
||||
if(hasRecipe(entity))
|
||||
{
|
||||
ItemStack existing = entity.outputItems.getStackInSlot(0);
|
||||
existing.setCount(existing.getCount()+1);
|
||||
if(existing.is(Items.AIR))
|
||||
{
|
||||
existing = makeOutputItem(entity.itemsHandler.getStackInSlot(0));
|
||||
}
|
||||
entity.itemsHandler.extractItem(0, 1, false);
|
||||
entity.outputItems.setStackInSlot(0, existing);
|
||||
|
||||
entity.resetProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasRecipe(ItemScrubberBlockEntity entity) {
|
||||
SimpleContainer inventory = new SimpleContainer(entity.itemsHandler.getSlots());
|
||||
for(int i=0;i<entity.itemsHandler.getSlots();i++)
|
||||
{
|
||||
inventory.setItem(i, entity.itemsHandler.getStackInSlot(i));
|
||||
}
|
||||
SimpleContainer output = new SimpleContainer(entity.outputItems.getSlots());
|
||||
for(int i=0;i<entity.outputItems.getSlots();i++)
|
||||
{
|
||||
output.setItem(i, entity.outputItems.getStackInSlot(i));
|
||||
}
|
||||
|
||||
|
||||
boolean hasAnItem = !entity.itemsHandler.getStackInSlot(0).isEmpty();
|
||||
|
||||
ItemStack result = null;
|
||||
if(hasAnItem)
|
||||
{
|
||||
result = makeOutputItem(entity.itemsHandler.getStackInSlot(0));
|
||||
|
||||
}
|
||||
return hasAnItem && canInsertIntoOutput(output, result);
|
||||
}
|
||||
|
||||
private static boolean canInsertIntoOutput(SimpleContainer inventory, ItemStack result) {
|
||||
ItemStack existing = inventory.getItem(0);
|
||||
boolean stackCompat = (existing.getMaxStackSize() > existing.getCount());
|
||||
boolean sameType = (existing.getItem() == result.getItem());
|
||||
boolean outputEmpty = existing.isEmpty();
|
||||
|
||||
if(outputEmpty)return true;
|
||||
return (stackCompat && sameType);
|
||||
}
|
||||
|
||||
private void resetProgress() {
|
||||
progress=0;
|
||||
|
||||
}
|
||||
|
||||
protected static ItemStack makeOutputItem(ItemStack original)
|
||||
{
|
||||
ItemStack newItem = new ItemStack(original.getItem(),1);
|
||||
return newItem;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package dev.zontreck.otemod.blocks.entity;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.blocks.ModBlocks;
|
||||
import dev.zontreck.otemod.implementation.vault.VaultMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModEntities {
|
||||
|
||||
public static final DeferredRegister<BlockEntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, OTEMod.MOD_ID);
|
||||
|
||||
public static final RegistryObject <BlockEntityType <ItemScrubberBlockEntity>> ITEM_SCRUBBER = ENTITIES.register("item_scrubber", ()-> BlockEntityType.Builder.of(ItemScrubberBlockEntity::new, ModBlocks.ITEM_SCRUBBER.get()).build(null));
|
||||
|
||||
|
||||
public static void register(IEventBus eventBus)
|
||||
{
|
||||
ENTITIES.register(eventBus);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package dev.zontreck.otemod.blocks.types;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Direction.Plane;
|
||||
import net.minecraft.world.level.block.IronBarsBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
|
||||
/** Pane block with sensible culling */
|
||||
public class AlternatePaneBlock extends IronBarsBlock {
|
||||
public static final EnumMap<Direction,BooleanProperty> DIRECTIONS;
|
||||
static {
|
||||
DIRECTIONS = new EnumMap<>(Direction.class);
|
||||
DIRECTIONS.put(Direction.NORTH, NORTH);
|
||||
DIRECTIONS.put(Direction.EAST, EAST);
|
||||
DIRECTIONS.put(Direction.SOUTH, SOUTH);
|
||||
DIRECTIONS.put(Direction.WEST, WEST);
|
||||
}
|
||||
|
||||
public AlternatePaneBlock(Properties builder) {
|
||||
super(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skipRendering(BlockState state, BlockState adjacentBlockState, Direction side) {
|
||||
// cull top and bottom if all props that we have are contained in the above or below
|
||||
if (adjacentBlockState.getBlock() == this && side.getAxis().isVertical()) {
|
||||
for (Direction dir : Plane.HORIZONTAL) {
|
||||
BooleanProperty prop = DIRECTIONS.get(dir);
|
||||
if (state.getValue(prop) && !adjacentBlockState.getValue(prop)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.skipRendering(state, adjacentBlockState, side);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ package dev.zontreck.otemod.commands.vaults;
|
|||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import dev.zontreck.otemod.implementation.VaultContainer;
|
||||
import dev.zontreck.otemod.implementation.vault.VaultContainer;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
|
|
@ -3,7 +3,7 @@ package dev.zontreck.otemod.commands.vaults;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
|
||||
import dev.zontreck.otemod.implementation.VaultContainer;
|
||||
import dev.zontreck.otemod.implementation.vault.VaultContainer;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
@ -50,6 +51,7 @@ public class Place {
|
|||
|
||||
Container cont = MemoryHolder.getContainer(play);
|
||||
List<StoredBlock> blocks = cont.blocks;
|
||||
Collections.shuffle(blocks);
|
||||
|
||||
if(cont.Pos1 != OTEMod.ZERO_VECTOR)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.zontreck.otemod.commands.zschem;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -58,7 +59,9 @@ public class PlaceAsAir {
|
|||
WorldProp system = WorldProp.acquire(cont.lvl);
|
||||
// Begin the process
|
||||
List<Vector3> positions = cont.Pos1.makeCube(cont.Pos2);
|
||||
Collections.shuffle(positions);
|
||||
Iterator<Vector3> v3 = positions.iterator();
|
||||
|
||||
while(v3.hasNext())
|
||||
{
|
||||
Vector3 pos = v3.next();
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package dev.zontreck.otemod.implementation;
|
||||
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class OutputItemStackHandler extends ItemStackHandler {
|
||||
private final ItemStackHandler internalSlot;
|
||||
|
||||
public OutputItemStackHandler(ItemStackHandler hidden) {
|
||||
super();
|
||||
internalSlot = hidden;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(int size) {
|
||||
stacks = NonNullList.<ItemStack>withSize(size, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(int slot, ItemStack stack) {
|
||||
internalSlot.setStackInSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return internalSlot.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return internalSlot.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
return internalSlot.extractItem(slot, amount, simulate);
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
package dev.zontreck.otemod.implementation;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.zontreck.otemod.implementation.inits.MenuInitializer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuConstructor;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
public class VaultMenu extends AbstractContainerMenu
|
||||
{
|
||||
//private final ContainerLevelAccess containerAccess;
|
||||
public final UUID VaultMenuID;
|
||||
|
||||
public VaultMenu (int id, Inventory player)
|
||||
{
|
||||
this(id, player, new ItemStackHandler(54), BlockPos.ZERO);
|
||||
}
|
||||
|
||||
public VaultMenu (int id, Inventory player, IItemHandler slots, BlockPos pos)
|
||||
{
|
||||
super(MenuInitializer.VAULT.get(), id);
|
||||
VaultMenuID=UUID.randomUUID();
|
||||
//this.containerAccess = ContainerLevelAccess.create(player.player.level, pos);
|
||||
|
||||
final int slotSize = 16;
|
||||
final int startX = 17;
|
||||
final int startY = 133;
|
||||
final int hotbarY = 184;
|
||||
final int inventoryY = 26;
|
||||
|
||||
for (int row = 0; row < 6; row++)
|
||||
{
|
||||
for (int column = 0; column < 9; column++)
|
||||
{
|
||||
addSlot(new SlotItemHandler(slots, row*9 + column, startX+column * slotSize , inventoryY + row * slotSize));
|
||||
}
|
||||
}
|
||||
|
||||
for (int row=0;row<3;row++)
|
||||
{
|
||||
for(int col = 0; col< 9; col++)
|
||||
{
|
||||
addSlot(new Slot(player, 9+row * 9 + col, startX + col * slotSize, startY + row * slotSize));
|
||||
}
|
||||
}
|
||||
|
||||
for(int col = 0; col<9; col++)
|
||||
{
|
||||
addSlot(new Slot(player, col, startX + col * slotSize, hotbarY));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player play, int index) {
|
||||
ItemStack ret = ItemStack.EMPTY;
|
||||
final Slot slot = getSlot(index);
|
||||
boolean moveStack = false;
|
||||
if(slot.hasItem()){
|
||||
final ItemStack item = slot.getItem();
|
||||
ret = item.copy();
|
||||
|
||||
if(index<54)
|
||||
{
|
||||
moveStack=moveItemStackTo(item, 54, this.slots.size(), true);
|
||||
if(!moveStack) return ItemStack.EMPTY;
|
||||
}else {
|
||||
moveStack = moveItemStackTo(item, 0, 54, false);
|
||||
|
||||
if(!moveStack)return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
|
||||
if(item.isEmpty()){
|
||||
slot.set(ItemStack.EMPTY);
|
||||
}else slot.setChanged();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player p_38874_) {
|
||||
return true; // We have no block
|
||||
}
|
||||
|
||||
public static MenuConstructor getServerMenu (ItemStackHandler inventory){
|
||||
return (id, player, play) -> new VaultMenu(id, player, inventory, BlockPos.ZERO);
|
||||
}
|
||||
|
||||
|
||||
public void doCommitAction()
|
||||
{
|
||||
|
||||
// Locate the Vault in the Vault Registry and commit changes.
|
||||
// Search for myself!
|
||||
for(Map.Entry<UUID,VaultContainer> e : VaultContainer.VAULT_REGISTRY.entrySet())
|
||||
{
|
||||
if(e.getValue().VaultID.equals(VaultMenuID))
|
||||
{
|
||||
e.getValue().commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package dev.zontreck.otemod.implementation.inits;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.implementation.VaultMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public final class MenuInitializer
|
||||
{
|
||||
public static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.MENU_TYPES, OTEMod.MOD_ID);
|
||||
|
||||
public static final RegistryObject <MenuType <VaultMenu>> VAULT = CONTAINERS.register("vault", ()-> new MenuType<>(VaultMenu::new));
|
||||
|
||||
|
||||
private MenuInitializer(){}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package dev.zontreck.otemod.implementation.inits;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import dev.zontreck.otemod.implementation.scrubber.ScrubberMenu;
|
||||
import dev.zontreck.otemod.implementation.vault.VaultMenu;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.network.IContainerFactory;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public final class ModMenuTypes
|
||||
{
|
||||
public static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.MENU_TYPES, OTEMod.MOD_ID);
|
||||
|
||||
public static final RegistryObject <MenuType <VaultMenu>> VAULT = CONTAINERS.register("vault", ()-> new MenuType<>(VaultMenu::new));
|
||||
|
||||
public static final RegistryObject<MenuType<ScrubberMenu>> SCRUBBER = registerMenuType(ScrubberMenu::new, "item_scrubber_menu");
|
||||
|
||||
|
||||
private static <T extends AbstractContainerMenu> RegistryObject<MenuType<T>> registerMenuType(IContainerFactory<T> factory, String name)
|
||||
{
|
||||
return CONTAINERS.register(name, ()->IForgeMenuType.create(factory));
|
||||
}
|
||||
|
||||
public static void register(IEventBus bus)
|
||||
{
|
||||
CONTAINERS.register(bus);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
package dev.zontreck.otemod.implementation.scrubber;
|
||||
|
||||
import dev.zontreck.otemod.blocks.ModBlocks;
|
||||
import dev.zontreck.otemod.blocks.entity.ItemScrubberBlockEntity;
|
||||
import dev.zontreck.otemod.implementation.inits.ModMenuTypes;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||
import net.minecraft.world.inventory.SimpleContainerData;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
public class ScrubberMenu extends AbstractContainerMenu
|
||||
{
|
||||
public final ItemScrubberBlockEntity entity;
|
||||
private final Level level;
|
||||
private final ContainerData data;
|
||||
|
||||
public ScrubberMenu(int id, Inventory inv, FriendlyByteBuf buf)
|
||||
{
|
||||
this(id, inv, inv.player.level.getBlockEntity(buf.readBlockPos()), new SimpleContainerData(1));
|
||||
}
|
||||
|
||||
public ScrubberMenu(int id, Inventory inv, BlockEntity entity, ContainerData data){
|
||||
super(ModMenuTypes.SCRUBBER.get(), id);
|
||||
|
||||
checkContainerSize(inv, 1);
|
||||
this.entity = (ItemScrubberBlockEntity)entity;
|
||||
this.data=data;
|
||||
this.level = inv.player.level;
|
||||
|
||||
addPlayerInventory(inv);
|
||||
addPlayerHotbar(inv);
|
||||
|
||||
this.entity.getCapability(ForgeCapabilities.ITEM_HANDLER, Direction.UP).ifPresent(handler->{
|
||||
addSlot(new SlotItemHandler(handler, 0, 16, 41));
|
||||
});
|
||||
this.entity.getCapability(ForgeCapabilities.ITEM_HANDLER, Direction.DOWN).ifPresent(handler->{
|
||||
addSlot(new SlotItemHandler(handler, 0, 177, 41));
|
||||
});
|
||||
|
||||
addDataSlots(data);
|
||||
|
||||
}
|
||||
|
||||
public boolean isCrafting()
|
||||
{
|
||||
return data.get(0) > 0;
|
||||
}
|
||||
|
||||
public int getScaledProgress()
|
||||
{
|
||||
if(!isCrafting())return 0;
|
||||
int progress = this.data.get(0);
|
||||
int max = ItemScrubberBlockEntity.MAXIMUM_PROCESSING_TICKS;
|
||||
|
||||
int progressArrow = 125;
|
||||
|
||||
|
||||
if(progress != 0 && max != 0)
|
||||
{
|
||||
int percent = progress * progressArrow / max;
|
||||
return percent;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// CREDIT GOES TO: diesieben07 | https://github.com/diesieben07/SevenCommons
|
||||
// must assign a slot number to each of the slots used by the GUI.
|
||||
// For this container, we can see both the tile inventory's slots as well as the player inventory slots and the hotbar.
|
||||
// Each time we add a Slot to the container, it automatically increases the slotIndex, which means
|
||||
// 0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 8)
|
||||
// 9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35)
|
||||
// 36 - 44 = TileInventory slots, which map to our TileEntity slot numbers 0 - 8)
|
||||
private static final int HOTBAR_SLOT_COUNT = 9;
|
||||
private static final int PLAYER_INVENTORY_ROW_COUNT = 3;
|
||||
private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
|
||||
private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
|
||||
private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;
|
||||
private static final int VANILLA_FIRST_SLOT_INDEX = 0;
|
||||
private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
|
||||
|
||||
// THIS YOU HAVE TO DEFINE!
|
||||
private static final int TE_INVENTORY_SLOT_COUNT = 2; // must be the number of slots you have!
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player playerIn, int index) {
|
||||
Slot sourceSlot = slots.get(index);
|
||||
if (sourceSlot == null || !sourceSlot.hasItem()) return ItemStack.EMPTY; //EMPTY_ITEM
|
||||
ItemStack sourceStack = sourceSlot.getItem();
|
||||
ItemStack copyOfSourceStack = sourceStack.copy();
|
||||
|
||||
// Check if the slot clicked is one of the vanilla container slots
|
||||
if (index < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) {
|
||||
// This is a vanilla container slot so merge the stack into the tile inventory
|
||||
if (!moveItemStackTo(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX
|
||||
+ TE_INVENTORY_SLOT_COUNT, false)) {
|
||||
return ItemStack.EMPTY; // EMPTY_ITEM
|
||||
}
|
||||
} else if (index < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) {
|
||||
// This is a TE slot so merge the stack into the players inventory
|
||||
if (!moveItemStackTo(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else {
|
||||
System.out.println("Invalid slotIndex:" + index);
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
// If stack size == 0 (the entire stack was moved) set slot contents to null
|
||||
if (sourceStack.getCount() == 0) {
|
||||
sourceSlot.set(ItemStack.EMPTY);
|
||||
} else {
|
||||
sourceSlot.setChanged();
|
||||
}
|
||||
sourceSlot.onTake(playerIn, sourceStack);
|
||||
return copyOfSourceStack;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return stillValid(ContainerLevelAccess.create(level, entity.getBlockPos()), player, ModBlocks.ITEM_SCRUBBER.get());
|
||||
}
|
||||
|
||||
private static final int PLAYER_INVENTORY_FIRST_SLOT_HEIGHT = 69;
|
||||
private static final int PLAYER_INVENTORY_FIRST_SLOT_LEFT = 24;
|
||||
private static final int PLAYER_HOTBAR_FIRST_SLOT = 125;
|
||||
|
||||
private void addPlayerInventory(Inventory inv)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 9; j++) {
|
||||
this.addSlot(new Slot(inv, j+i*9+9, PLAYER_INVENTORY_FIRST_SLOT_LEFT+j*18, PLAYER_INVENTORY_FIRST_SLOT_HEIGHT+i*18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addPlayerHotbar(Inventory inv)
|
||||
{
|
||||
for (int index = 0; index < 9; index++) {
|
||||
this.addSlot(new Slot(inv, index, PLAYER_INVENTORY_FIRST_SLOT_LEFT+index*18, PLAYER_HOTBAR_FIRST_SLOT));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package dev.zontreck.otemod.implementation.scrubber;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class ScrubberScreen extends AbstractContainerScreen<ScrubberMenu>
|
||||
{
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation(OTEMod.MOD_ID, "textures/gui/item_scrubber_gui.png");
|
||||
|
||||
public ScrubberScreen(ScrubberMenu p_97741_, Inventory p_97742_, Component p_97743_) {
|
||||
super(p_97741_, p_97742_, p_97743_);
|
||||
|
||||
|
||||
this.topPos=0;
|
||||
this.leftPos=0;
|
||||
|
||||
this.imageWidth = 207;
|
||||
this.imageHeight = 164;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
super.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg(PoseStack poseStack, float partialTick, int mouseX, int mouseY) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderTexture(0, TEXTURE);
|
||||
|
||||
|
||||
blit(poseStack, this.leftPos, this.topPos, 0,0, imageWidth, imageHeight);
|
||||
renderUncraftingProgress(poseStack);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void renderLabels(PoseStack stack, int mouseX, int mouseY)
|
||||
{
|
||||
this.font.draw(stack, this.title.getString(), 63, 12, 0xFFFFFF);
|
||||
|
||||
//this.font.draw(stack, this.playerInventoryTitle.getString(), this.leftPos + 17, this.topPos + 123, 0xFFFFFF);
|
||||
}
|
||||
|
||||
private void renderUncraftingProgress(PoseStack stack)
|
||||
{
|
||||
if(menu.isCrafting())
|
||||
{
|
||||
blit(stack, leftPos+42, topPos+45, 1, 168, menu.getScaledProgress(),6);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack stack, int mouseX, int mouseY, float delta)
|
||||
{
|
||||
renderBackground(stack);
|
||||
super.render(stack, mouseX, mouseY, delta);
|
||||
renderTooltip(stack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package dev.zontreck.otemod.implementation;
|
||||
package dev.zontreck.otemod.implementation.vault;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
|
@ -0,0 +1,147 @@
|
|||
package dev.zontreck.otemod.implementation.vault;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.zontreck.otemod.implementation.inits.ModMenuTypes;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuConstructor;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
public class VaultMenu extends AbstractContainerMenu
|
||||
{
|
||||
//private final ContainerLevelAccess containerAccess;
|
||||
public final UUID VaultMenuID;
|
||||
|
||||
public VaultMenu (int id, Inventory player)
|
||||
{
|
||||
this(id, player, new ItemStackHandler(54), BlockPos.ZERO);
|
||||
}
|
||||
|
||||
public VaultMenu (int id, Inventory player, IItemHandler slots, BlockPos pos)
|
||||
{
|
||||
super(ModMenuTypes.VAULT.get(), id);
|
||||
VaultMenuID=UUID.randomUUID();
|
||||
//this.containerAccess = ContainerLevelAccess.create(player.player.level, pos);
|
||||
|
||||
final int slotSize = 18;
|
||||
final int startX = 24;
|
||||
final int inventoryY = 38;
|
||||
|
||||
addPlayerInventory(player);
|
||||
addPlayerHotbar(player);
|
||||
|
||||
|
||||
for (int row = 0; row < 6; row++)
|
||||
{
|
||||
for (int column = 0; column < 9; column++)
|
||||
{
|
||||
addSlot(new SlotItemHandler(slots, row*9 + column, startX+column * slotSize , inventoryY + row * slotSize));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CREDIT GOES TO: diesieben07 | https://github.com/diesieben07/SevenCommons
|
||||
// must assign a slot number to each of the slots used by the GUI.
|
||||
// For this container, we can see both the tile inventory's slots as well as the player inventory slots and the hotbar.
|
||||
// Each time we add a Slot to the container, it automatically increases the slotIndex, which means
|
||||
// 0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 8)
|
||||
// 9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35)
|
||||
// 36 - 44 = TileInventory slots, which map to our TileEntity slot numbers 0 - 8)
|
||||
private static final int HOTBAR_SLOT_COUNT = 9;
|
||||
private static final int PLAYER_INVENTORY_ROW_COUNT = 3;
|
||||
private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
|
||||
private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
|
||||
private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;
|
||||
private static final int VANILLA_FIRST_SLOT_INDEX = 0;
|
||||
private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
|
||||
|
||||
// THIS YOU HAVE TO DEFINE!
|
||||
private static final int TE_INVENTORY_SLOT_COUNT = 54; // must be the number of slots you have!
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player playerIn, int index) {
|
||||
Slot sourceSlot = slots.get(index);
|
||||
if (sourceSlot == null || !sourceSlot.hasItem()) return ItemStack.EMPTY; //EMPTY_ITEM
|
||||
ItemStack sourceStack = sourceSlot.getItem();
|
||||
ItemStack copyOfSourceStack = sourceStack.copy();
|
||||
|
||||
// Check if the slot clicked is one of the vanilla container slots
|
||||
if (index < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) {
|
||||
// This is a vanilla container slot so merge the stack into the tile inventory
|
||||
if (!moveItemStackTo(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX
|
||||
+ TE_INVENTORY_SLOT_COUNT, false)) {
|
||||
return ItemStack.EMPTY; // EMPTY_ITEM
|
||||
}
|
||||
} else if (index < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) {
|
||||
// This is a TE slot so merge the stack into the players inventory
|
||||
if (!moveItemStackTo(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else {
|
||||
System.out.println("Invalid slotIndex:" + index);
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
// If stack size == 0 (the entire stack was moved) set slot contents to null
|
||||
if (sourceStack.getCount() == 0) {
|
||||
sourceSlot.set(ItemStack.EMPTY);
|
||||
} else {
|
||||
sourceSlot.setChanged();
|
||||
}
|
||||
sourceSlot.onTake(playerIn, sourceStack);
|
||||
return copyOfSourceStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player p_38874_) {
|
||||
return true; // We have no block
|
||||
}
|
||||
|
||||
public static MenuConstructor getServerMenu (ItemStackHandler inventory){
|
||||
return (id, player, play) -> new VaultMenu(id, player, inventory, BlockPos.ZERO);
|
||||
}
|
||||
|
||||
|
||||
public void doCommitAction()
|
||||
{
|
||||
|
||||
// Locate the Vault in the Vault Registry and commit changes.
|
||||
// Search for myself!
|
||||
for(Map.Entry<UUID,VaultContainer> e : VaultContainer.VAULT_REGISTRY.entrySet())
|
||||
{
|
||||
if(e.getValue().VaultID.equals(VaultMenuID))
|
||||
{
|
||||
e.getValue().commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final int PLAYER_INVENTORY_FIRST_SLOT_HEIGHT = 156;
|
||||
private static final int PLAYER_INVENTORY_FIRST_SLOT_LEFT = 24;
|
||||
private static final int PLAYER_HOTBAR_FIRST_SLOT = 212;
|
||||
|
||||
private void addPlayerInventory(Inventory inv)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 9; j++) {
|
||||
this.addSlot(new Slot(inv, j+i*9+9, PLAYER_INVENTORY_FIRST_SLOT_LEFT+j*18, PLAYER_INVENTORY_FIRST_SLOT_HEIGHT+i*18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addPlayerHotbar(Inventory inv)
|
||||
{
|
||||
for (int index = 0; index < 9; index++) {
|
||||
this.addSlot(new Slot(inv, index, PLAYER_INVENTORY_FIRST_SLOT_LEFT+index*18, PLAYER_HOTBAR_FIRST_SLOT));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package dev.zontreck.otemod.implementation;
|
||||
package dev.zontreck.otemod.implementation.vault;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -26,8 +26,8 @@ public class VaultScreen extends AbstractContainerScreen <VaultMenu>
|
|||
this.leftPos = 0;
|
||||
this.topPos = 0;
|
||||
|
||||
this.imageWidth = 176;
|
||||
this.imageHeight = 224;
|
||||
this.imageWidth = 207;
|
||||
this.imageHeight = 238;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,13 +37,13 @@ public class VaultScreen extends AbstractContainerScreen <VaultMenu>
|
|||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
this.renderTooltip(stack, mouseX, mouseY);
|
||||
|
||||
this.font.draw(stack, this.title, this.leftPos + 17, this.topPos + 15, 0xFFFFFF);
|
||||
this.font.draw(stack, this.playerInventoryTitle, this.leftPos + 17, this.topPos + 123, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels(PoseStack stack, int mouseX, int mouseY)
|
||||
{
|
||||
this.font.draw(stack, this.title, 63, 12, 0xFFFFFF);
|
||||
this.font.draw(stack, this.playerInventoryTitle, 63, 146, 0xFFFFFF);
|
||||
//this.font.draw(stack, this.title.getString(), this.leftPos + 17, this.topPos + 15, 0xFFFFFF);
|
||||
|
||||
//this.font.draw(stack, this.playerInventoryTitle.getString(), this.leftPos + 17, this.topPos + 123, 0xFFFFFF);
|
|
@ -1,11 +1,9 @@
|
|||
package dev.zontreck.otemod.implementation;
|
||||
package dev.zontreck.otemod.implementation.vault;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.zontreck.otemod.OTEMod;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
@ -14,11 +12,10 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|||
@EventBusSubscriber(modid=OTEMod.MOD_ID,bus=Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public class VaultWatcher {
|
||||
|
||||
|
||||
@OnlyIn(Dist.DEDICATED_SERVER)
|
||||
@SubscribeEvent
|
||||
public void onClosedContainer(PlayerContainerEvent.Close ev)
|
||||
{
|
||||
if(ev.getEntity().level.isClientSide)return;
|
||||
//OTEMod.LOGGER.info("Player closed a container");
|
||||
// Player closed the container
|
||||
// Check if it is a vault Container
|
|
@ -22,6 +22,13 @@ public class ModItems {
|
|||
|
||||
public static final RegistryObject<Item> ETERNIUM_RAW_ORE = ITEMS.register("eternium_ore", () -> new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
|
||||
public static final RegistryObject<Item> RAW_COBALT = ITEMS.register("raw_cobalt", () -> new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
public static final RegistryObject<Item> COBALT_NUGGET = ITEMS.register("cobalt_nugget", () -> new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
public static final RegistryObject<Item> COBALT_INGOT = ITEMS.register("cobalt_ingot", () -> new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
public static final RegistryObject<Item> PATTERN = ITEMS.register("pattern", () -> new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
public static final RegistryObject<Item> SCORCHED_BRICK = ITEMS.register("scorched_brick", () -> new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
public static final RegistryObject<Item> COPPER_CAN = ITEMS.register("copper_can", () -> new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC).stacksTo(16)));
|
||||
|
||||
|
||||
public static void register(IEventBus bus){
|
||||
ITEMS.register(bus);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package dev.zontreck.otemod.recipes;
|
||||
|
||||
public class ModRecipes {
|
||||
|
||||
}
|
Reference in a new issue