🏗️ Configs, other mods compact init, art
This commit is contained in:
@@ -3,14 +3,17 @@ package com.oierbravo.trading_station;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import com.oierbravo.trading_station.compat.Mods;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationConfig;
|
||||
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||
import com.oierbravo.trading_station.registrate.*;
|
||||
import com.tterrag.registrate.Registrate;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraftforge.common.util.Lazy;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -44,15 +47,29 @@ public class TradingStation
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
ModCreativeTab modTab = new ModCreativeTab();
|
||||
|
||||
ModBlocks.register();
|
||||
ModBlockEntities.register();
|
||||
ModRecipes.register(modEventBus);
|
||||
ModMessages.register();
|
||||
ModMenus.register();
|
||||
Config.register();
|
||||
|
||||
registrate().addRawLang("itemGroup.trading_station:main", "Trading Station");
|
||||
TradingStationRegistrate.register();
|
||||
PoweredTradingStationRegistrate.register();
|
||||
|
||||
ModRecipes.register(modEventBus);
|
||||
ModMessages.register();
|
||||
|
||||
modEventBus.addListener(EventPriority.LOWEST, TradingStation::gatherData);
|
||||
|
||||
Mods.CREATE.executeIfInstalled(() -> MechanicalTradingStationRegistrate::register);
|
||||
}
|
||||
public static void gatherData(GatherDataEvent event) {
|
||||
DataGenerator gen = event.getGenerator();
|
||||
if (event.includeClient()) {
|
||||
registerLanguageKeys();
|
||||
}
|
||||
if (event.includeServer()) {
|
||||
|
||||
}
|
||||
}
|
||||
private static void registerLanguageKeys(){
|
||||
registrate().addRawLang("itemGroup.trading_station", "Trading Station");
|
||||
registrate().addRawLang(ModLang.key("trading_station.block.display"), "Trading Station");
|
||||
registrate().addRawLang(ModLang.key("powered_trading_station.block.display"), "Powered Trading Station");
|
||||
registrate().addRawLang(ModLang.key("trading.recipe"), "Trading recipe");
|
||||
@@ -61,10 +78,7 @@ public class TradingStation
|
||||
registrate().addRawLang(ModLang.key("select_target.button"), "Select target");
|
||||
registrate().addRawLang(ModLang.key("select_target.clear"), "Clear");
|
||||
registrate().addRawLang("config.jade.plugin_trading_station.trading_station_data", "Trading Station data");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Registrate registrate() {
|
||||
return REGISTRATE.get();
|
||||
}
|
||||
|
||||
61
src/main/java/com/oierbravo/trading_station/compat/Mods.java
Normal file
61
src/main/java/com/oierbravo/trading_station/compat/Mods.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package com.oierbravo.trading_station.compat;
|
||||
|
||||
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
/**
|
||||
* From Create mod.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* For compatibility with and without another mod present, we have to define load conditions of the specific code
|
||||
*/
|
||||
public enum Mods {
|
||||
CREATE,
|
||||
ARS_NOUVEAU;
|
||||
|
||||
/**
|
||||
* @return a boolean of whether the mod is loaded or not based on mod id
|
||||
*/
|
||||
public boolean isLoaded() {
|
||||
return ModList.get().isLoaded(asId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mod id
|
||||
*/
|
||||
public String asId() {
|
||||
return ModLang.asId(name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple hook to run code if a mod is installed
|
||||
* @param toRun will be run only if the mod is loaded
|
||||
* @return Optional.empty() if the mod is not loaded, otherwise an Optional of the return value of the given supplier
|
||||
*/
|
||||
public <T> Optional<T> runIfInstalled(Supplier<Supplier<T>> toRun) {
|
||||
if (isLoaded())
|
||||
return Optional.of(toRun.get().get());
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple hook to execute code if a mod is installed
|
||||
* @param toExecute will be executed only if the mod is loaded
|
||||
*/
|
||||
public void executeIfInstalled(Supplier<Runnable> toExecute) {
|
||||
if (isLoaded()) {
|
||||
toExecute.get().run();
|
||||
}
|
||||
}
|
||||
|
||||
public Block getBlock(String id) {
|
||||
return ForgeRegistries.BLOCKS.getValue(new ResourceLocation(asId(), id));
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@ package com.oierbravo.trading_station.compat.jei;
|
||||
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
||||
import com.oierbravo.trading_station.registrate.ModBlocks;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationConfig;
|
||||
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
||||
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||
import mezz.jei.api.IModPlugin;
|
||||
import mezz.jei.api.JeiPlugin;
|
||||
import mezz.jei.api.recipe.RecipeType;
|
||||
@@ -33,8 +35,8 @@ public class JEIPlugin implements IModPlugin {
|
||||
|
||||
@Override
|
||||
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
|
||||
registration.addRecipeCatalyst(new ItemStack(ModBlocks.TRADING_STATION.get()),new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class));
|
||||
registration.addRecipeCatalyst(new ItemStack(ModBlocks.POWERED_TRADING_STATION.get()),new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class));
|
||||
registration.addRecipeCatalyst(new ItemStack(TradingStationRegistrate.TRADING_STATION_BLOCK.get()),new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class));
|
||||
registration.addRecipeCatalyst(new ItemStack(PoweredTradingStationRegistrate.POWERED_TRADING_STATION_BLOCK.get()),new RecipeType<>(TradingRecipeCategory.UID, TradingRecipe.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
||||
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||
import com.oierbravo.trading_station.registrate.ModBlocks;
|
||||
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||
import mezz.jei.api.constants.VanillaTypes;
|
||||
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
|
||||
import mezz.jei.api.gui.drawable.IDrawable;
|
||||
@@ -26,6 +26,7 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -63,7 +64,7 @@ public class TradingRecipeCategory implements IRecipeCategory<TradingRecipe> {
|
||||
|
||||
}
|
||||
};
|
||||
this.icon = helper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(ModBlocks.TRADING_STATION.get()));
|
||||
this.icon = helper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(TradingStationRegistrate.TRADING_STATION_BLOCK.get()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.oierbravo.trading_station.content.trading_station;
|
||||
|
||||
import com.oierbravo.trading_station.registrate.ModBlockEntities;
|
||||
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
||||
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
@@ -8,7 +9,6 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
@@ -79,7 +79,7 @@ public class TradingStationBlock extends BaseEntityBlock {
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
||||
return ModBlockEntities.TRADING_STATION.create(pPos, pState);
|
||||
return TradingStationRegistrate.TRADING_STATION_BLOCK_ENTITY.create(pPos, pState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,7 +95,7 @@ public class TradingStationBlock extends BaseEntityBlock {
|
||||
if(pLevel.isClientSide()) {
|
||||
return null;
|
||||
}
|
||||
return createTickerHelper(pBlockEntityType, ModBlockEntities.TRADING_STATION.get(),
|
||||
return createTickerHelper(pBlockEntityType, TradingStationRegistrate.TRADING_STATION_BLOCK_ENTITY.get(),
|
||||
(pLevel1, pPos, pState1, pBlockEntity) -> pBlockEntity.tick(pLevel1, pPos, pState1));
|
||||
}
|
||||
|
||||
|
||||
@@ -57,13 +57,11 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
private BlockState lastBlockState;
|
||||
|
||||
protected final ContainerData containerData;
|
||||
private Item preferedItem;
|
||||
|
||||
public TradingStationBlockEntity(BlockEntityType<?> pType, BlockPos pWorldPosition, BlockState pBlockState) {
|
||||
super(pType, pWorldPosition, pBlockState);
|
||||
updateTag = getPersistentData();
|
||||
lastBlockState = this.getBlockState();
|
||||
preferedItem = ItemStack.EMPTY.getItem();
|
||||
containerData = TradingStationBlockEntity.createContainerData(this);
|
||||
}
|
||||
public static ContainerData createContainerData(TradingStationBlockEntity pBlockEntity){
|
||||
@@ -99,6 +97,7 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
setChanged();
|
||||
resetProgress();
|
||||
if(!level.isClientSide()) {
|
||||
ModMessages.sendToClients(new ItemStackSyncS2CPacket(slot,this.getStackInSlot(0), worldPosition, ItemStackSyncS2CPacket.SlotType.TARGET));
|
||||
}
|
||||
@@ -127,9 +126,11 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
|
||||
private ItemStackHandler createInputItemHandler() {
|
||||
return new ItemStackHandler(2) {
|
||||
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
setChanged();
|
||||
resetProgress();
|
||||
if(!level.isClientSide()) {
|
||||
ModMessages.sendToClients(new ItemStackSyncS2CPacket(slot,this.getStackInSlot(0), worldPosition, ItemStackSyncS2CPacket.SlotType.INPUT));
|
||||
}
|
||||
@@ -206,7 +207,6 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
tag.put("target", targetItemHandler.serializeNBT());
|
||||
tag.putInt("trading_station.progress", progress);
|
||||
tag.putInt("trading_station.maxProgress", maxProgress);
|
||||
String preferedItemString = ForgeRegistries.ITEMS.getKey(preferedItem).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,8 +217,6 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
targetItemHandler.deserializeNBT(tag.getCompound("target"));
|
||||
progress = tag.getInt("trading_station.progress");
|
||||
maxProgress = tag.getInt("trading_station.maxProgress");
|
||||
String preferedItemString = tag.getString("trading_station.preferedItem");
|
||||
preferedItem = ForgeRegistries.ITEMS.getValue( ResourceLocation.tryParse(preferedItemString));
|
||||
}
|
||||
|
||||
public void drops() {
|
||||
@@ -256,25 +254,20 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
}
|
||||
if(!isPowered(this))
|
||||
return;
|
||||
if(!canCraftItem())
|
||||
return;
|
||||
|
||||
if (canCraftItem()) {
|
||||
this.updateProgress();
|
||||
BlockEntity.setChanged(pLevel, pPos, pState);
|
||||
this.maxProgress = this.getProcessingTime(this);
|
||||
if (this.progress > this.maxProgress) {
|
||||
craftItem();
|
||||
}
|
||||
BlockEntity.setChanged(pLevel, pPos, pState);
|
||||
|
||||
} else {
|
||||
this.resetProgress();
|
||||
BlockEntity.setChanged(pLevel, pPos, pState);
|
||||
this.updateProgress();
|
||||
BlockEntity.setChanged(pLevel, pPos, pState);
|
||||
this.maxProgress = this.getProcessingTime(this);
|
||||
if (this.progress > this.maxProgress) {
|
||||
craftItem();
|
||||
}
|
||||
|
||||
|
||||
BlockEntity.setChanged(pLevel, pPos, pState);
|
||||
}
|
||||
|
||||
protected void updateProgress(){
|
||||
this.progress += 1;
|
||||
this.progress += TradingStationConfig.PROGRESS_PER_TICK.get();
|
||||
|
||||
}
|
||||
private static boolean isPowered(TradingStationBlockEntity pBlockEntity){
|
||||
@@ -299,7 +292,6 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
return inputInventory;
|
||||
}
|
||||
private void craftItem() {
|
||||
Level level = this.getLevel();
|
||||
SimpleContainer inputInventory = getInputInventory(this);
|
||||
|
||||
Optional<TradingRecipe> recipe = getRecipe(this);
|
||||
@@ -320,33 +312,25 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
}
|
||||
|
||||
this.resetProgress();
|
||||
this.setChanged();
|
||||
}
|
||||
|
||||
|
||||
protected boolean canCraftItem() {
|
||||
Level level = this.getLevel();
|
||||
if(level == null)
|
||||
return false;
|
||||
|
||||
SimpleContainer inputInventory = getInputInventory(this);
|
||||
|
||||
Optional<TradingRecipe> match = getRecipe(this);
|
||||
|
||||
if(match.isEmpty()) {
|
||||
if(!match.isPresent()) {
|
||||
return false;
|
||||
}
|
||||
//return false;
|
||||
return match.isPresent()
|
||||
&& TradingStationBlockEntity.hasEnoughInputItems(inputInventory,match.get().getIngredients())
|
||||
&& TradingStationBlockEntity.hasEnoughOutputSpace(this.outputItems,match.get().getResultItem());
|
||||
return hasEnoughInputItems(inputInventory, match.get().getIngredients())
|
||||
&& hasEnoughOutputSpace(this.outputItems, match.get().getResultItem());
|
||||
}
|
||||
|
||||
private boolean canProcess(ItemStack stack) {
|
||||
|
||||
return getRecipe(this).isPresent();
|
||||
}
|
||||
protected static boolean hasEnoughInputItems(SimpleContainer inventory, NonNullList<Ingredient> ingredients){
|
||||
protected boolean hasEnoughInputItems(SimpleContainer inventory, NonNullList<Ingredient> ingredients){
|
||||
int enough = 0;
|
||||
for(int ingredientIndex = 0; ingredientIndex < ingredients.size();ingredientIndex ++){
|
||||
Ingredient ingredient = ingredients.get(ingredientIndex);
|
||||
@@ -360,7 +344,7 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
||||
return ingredients.size() == enough;
|
||||
}
|
||||
|
||||
protected static boolean hasEnoughOutputSpace(ItemStackHandler stackHandler,ItemStack resultItemStack){
|
||||
protected boolean hasEnoughOutputSpace(ItemStackHandler stackHandler,ItemStack resultItemStack){
|
||||
return stackHandler.getStackInSlot(0).isEmpty() || stackHandler.getStackInSlot(0).is(resultItemStack.getItem()) && stackHandler.getStackInSlot(0).getMaxStackSize() - stackHandler.getStackInSlot(0).getCount() >= resultItemStack.getCount() ;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,15 @@ package com.oierbravo.trading_station.content.trading_station;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
|
||||
public class TradingStationConfig {
|
||||
//public static ForgeConfigSpec.IntValue MELTER_CAPACITY;
|
||||
//public static ForgeConfigSpec.IntValue MELTER_FLUID_PER_TICK;
|
||||
public static ForgeConfigSpec.IntValue PROGRESS_PER_TICK;
|
||||
|
||||
public static void registerServerConfig(ForgeConfigSpec.Builder COMMON_BUILDER) {
|
||||
/* SERVER_BUILDER.comment("Settings for the trading_station").push("trading_station");
|
||||
MELTER_CAPACITY = SERVER_BUILDER
|
||||
.comment("How much liquid fits into the trading_station, in mB")
|
||||
.defineInRange("capacity", 1000, 1, Integer.MAX_VALUE);
|
||||
MELTER_FLUID_PER_TICK = SERVER_BUILDER
|
||||
.comment("How much liquid generates per tick, in mB")
|
||||
.defineInRange("liquidPerTick", 2, 1, Integer.MAX_VALUE);
|
||||
SERVER_BUILDER.pop();*/
|
||||
public static void registerCommonConfig(ForgeConfigSpec.Builder COMMON_BUILDER) {
|
||||
COMMON_BUILDER.comment("Settings for the trading_station").push("trading_station");
|
||||
PROGRESS_PER_TICK = COMMON_BUILDER
|
||||
.comment("How much progress per tick")
|
||||
.defineInRange("progressPerTick", 1, 1, Integer.MAX_VALUE);
|
||||
COMMON_BUILDER.pop();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,25 @@
|
||||
package com.oierbravo.trading_station.content.trading_station;
|
||||
|
||||
import com.oierbravo.trading_station.foundation.gui.AbstractTradingMenu;
|
||||
import com.oierbravo.trading_station.registrate.ModBlocks;
|
||||
import com.oierbravo.trading_station.registrate.ModMenus;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import com.oierbravo.trading_station.registrate.TradingStationRegistrate;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.*;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TradingStationMenu extends AbstractTradingMenu {
|
||||
protected final int[] outputSlotCoords = {131,38};
|
||||
|
||||
public TradingStationMenu(int pContainerId, Inventory pInv, BlockEntity pBlockEntity, ContainerData pData) {
|
||||
super(ModMenus.TRADING_STATION.get(), pContainerId, pInv, pBlockEntity, pData);
|
||||
super(TradingStationRegistrate.TRADING_STATION_MENU.get(), pContainerId, pInv, pBlockEntity, pData);
|
||||
}
|
||||
|
||||
public TradingStationMenu(int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
||||
super(ModMenus.TRADING_STATION.get(), pContainerId, inventory, buf);
|
||||
super(TradingStationRegistrate.TRADING_STATION_MENU.get(), pContainerId, inventory, buf);
|
||||
}
|
||||
|
||||
public static TradingStationMenu factory(@Nullable MenuType<TradingStationMenu> pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
||||
@@ -35,7 +27,7 @@ public class TradingStationMenu extends AbstractTradingMenu {
|
||||
}
|
||||
@Override
|
||||
public boolean stillValid(Player pPlayer) {
|
||||
return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()), pPlayer, ModBlocks.TRADING_STATION.get());
|
||||
return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()), pPlayer, TradingStationRegistrate.TRADING_STATION_BLOCK.get());
|
||||
}
|
||||
@Override
|
||||
public int[][] getInputSlotCoords() {
|
||||
|
||||
@@ -1,39 +1,21 @@
|
||||
package com.oierbravo.trading_station.content.trading_station.powered;
|
||||
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlock;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
||||
import com.oierbravo.trading_station.registrate.ModBlockEntities;
|
||||
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
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.RenderShape;
|
||||
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.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.HORIZONTAL_FACING;
|
||||
|
||||
|
||||
public class PoweredTradingStationBlock extends TradingStationBlock {
|
||||
|
||||
@@ -45,7 +27,7 @@ public class PoweredTradingStationBlock extends TradingStationBlock {
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
||||
return ModBlockEntities.POWERED_TRADING_STATION.create(pPos, pState);
|
||||
return PoweredTradingStationRegistrate.POWERED_TRADING_STATION_BLOCK_ENTITY.create(pPos, pState);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -54,7 +36,7 @@ public class PoweredTradingStationBlock extends TradingStationBlock {
|
||||
if(pLevel.isClientSide()) {
|
||||
return null;
|
||||
}
|
||||
return createTickerHelper(pBlockEntityType, ModBlockEntities.POWERED_TRADING_STATION.get(),
|
||||
return createTickerHelper(pBlockEntityType, PoweredTradingStationRegistrate.POWERED_TRADING_STATION_BLOCK_ENTITY.get(),
|
||||
(pLevel1, pPos, pState1, pBlockEntity) -> pBlockEntity.tick(pLevel1, pPos, pState1));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.oierbravo.trading_station.content.trading_station.powered;
|
||||
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationConfig;
|
||||
import com.oierbravo.trading_station.foundation.util.ModEnergyStorage;
|
||||
import com.oierbravo.trading_station.foundation.util.ModLang;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -38,7 +39,7 @@ public class PoweredTradingStationBlockEntity extends TradingStationBlockEntity
|
||||
super(pType, pWorldPosition, pBlockState);
|
||||
}
|
||||
private ModEnergyStorage createEnergyStorage() {
|
||||
return new ModEnergyStorage(64000, 200) {
|
||||
return new ModEnergyStorage(PoweredTradingStationConfig.ENERGY_CAPACITY.get(), PoweredTradingStationConfig.ENERGY_TRANSFER.get()) {
|
||||
@Override
|
||||
public void onEnergyChanged() {
|
||||
setChanged();
|
||||
@@ -94,11 +95,11 @@ public class PoweredTradingStationBlockEntity extends TradingStationBlockEntity
|
||||
|
||||
@Override
|
||||
protected void updateProgress() {
|
||||
super.updateProgress();
|
||||
this.progress += PoweredTradingStationConfig.PROGRESS_PER_TICK.get();
|
||||
extractEnergy();
|
||||
}
|
||||
private void extractEnergy() {
|
||||
this.energyStorage.extractEnergy(1000, false);
|
||||
this.energyStorage.extractEnergy(PoweredTradingStationConfig.ENERGY_PER_TICK.get(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,7 +108,7 @@ public class PoweredTradingStationBlockEntity extends TradingStationBlockEntity
|
||||
if(level == null)
|
||||
return false;
|
||||
|
||||
if(this.energyStorage.getEnergyStored() < 1000){
|
||||
if(this.energyStorage.getEnergyStored() < PoweredTradingStationConfig.ENERGY_PER_TICK.get()){
|
||||
return false;
|
||||
}
|
||||
return super.canCraftItem();
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.oierbravo.trading_station.content.trading_station.powered;
|
||||
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
|
||||
public class PoweredTradingStationConfig {
|
||||
public static ForgeConfigSpec.IntValue PROGRESS_PER_TICK;
|
||||
public static ForgeConfigSpec.IntValue ENERGY_CAPACITY;
|
||||
public static ForgeConfigSpec.IntValue ENERGY_TRANSFER;
|
||||
public static ForgeConfigSpec.IntValue ENERGY_PER_TICK;
|
||||
|
||||
public static void registerCommonConfig(ForgeConfigSpec.Builder COMMON_BUILDER) {
|
||||
COMMON_BUILDER.comment("Settings for the Powered Trading Station").push("powered_trading_station");
|
||||
PROGRESS_PER_TICK = COMMON_BUILDER
|
||||
.comment("How much progress per tick")
|
||||
.defineInRange("progressPerTick", 1, 1, Integer.MAX_VALUE);
|
||||
ENERGY_CAPACITY = COMMON_BUILDER
|
||||
.comment("How much energy capacity has")
|
||||
.defineInRange("energyCapacity", 64000, 1, Integer.MAX_VALUE);
|
||||
ENERGY_TRANSFER = COMMON_BUILDER
|
||||
.comment("How much energy can transfer")
|
||||
.defineInRange("energyTransfer", 200, 1, Integer.MAX_VALUE);
|
||||
ENERGY_PER_TICK = COMMON_BUILDER
|
||||
.comment("How much energy can transfer")
|
||||
.defineInRange("energyPerTick", 1000, 1, Integer.MAX_VALUE);
|
||||
COMMON_BUILDER.pop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +1,23 @@
|
||||
package com.oierbravo.trading_station.content.trading_station.powered;
|
||||
|
||||
import com.oierbravo.trading_station.content.trading_station.ITradingStationBlockEntity;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationMenu;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationScreen;
|
||||
import com.oierbravo.trading_station.foundation.gui.AbstractTradingMenu;
|
||||
import com.oierbravo.trading_station.registrate.ModBlocks;
|
||||
import com.oierbravo.trading_station.registrate.ModMenus;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import com.oierbravo.trading_station.registrate.PoweredTradingStationRegistrate;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.*;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PoweredTradingStationMenu extends AbstractTradingMenu {
|
||||
public PoweredTradingStationMenu(int pContainerId, Inventory pInv, BlockEntity pBlockEntity, ContainerData pData) {
|
||||
super(ModMenus.POWERED_TRADING_STATION.get(), pContainerId, pInv, pBlockEntity, pData);
|
||||
super(PoweredTradingStationRegistrate.POWERED_TRADING_STATION_MENU.get(), pContainerId, pInv, pBlockEntity, pData);
|
||||
}
|
||||
|
||||
public PoweredTradingStationMenu(int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
||||
super(ModMenus.POWERED_TRADING_STATION.get(), pContainerId, inventory, buf);
|
||||
super(PoweredTradingStationRegistrate.POWERED_TRADING_STATION_MENU.get(), pContainerId, inventory, buf);
|
||||
}
|
||||
|
||||
public static PoweredTradingStationMenu factory(@Nullable MenuType<PoweredTradingStationMenu> pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
|
||||
@@ -34,7 +25,7 @@ public class PoweredTradingStationMenu extends AbstractTradingMenu {
|
||||
}
|
||||
@Override
|
||||
public boolean stillValid(Player pPlayer) {
|
||||
return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()), pPlayer, ModBlocks.POWERED_TRADING_STATION.get());
|
||||
return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()), pPlayer, PoweredTradingStationRegistrate.POWERED_TRADING_STATION_BLOCK.get());
|
||||
}
|
||||
@Override
|
||||
public int[][] getInputSlotCoords() {
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
package com.oierbravo.trading_station.foundation.gui;
|
||||
|
||||
import com.oierbravo.trading_station.content.trading_station.ITradingStationBlockEntity;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationScreen;
|
||||
import com.oierbravo.trading_station.registrate.ModBlocks;
|
||||
import com.oierbravo.trading_station.registrate.ModMenus;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
@@ -3,8 +3,12 @@ package com.oierbravo.trading_station.foundation.util;
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public class ModLang {
|
||||
import java.util.Locale;
|
||||
|
||||
public class ModLang {
|
||||
public static String asId(String name) {
|
||||
return name.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
public static Component translate(String key){
|
||||
return Component.translatable(TradingStation.MODID + '.' + key);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.oierbravo.trading_station.registrate;
|
||||
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationConfig;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationConfig;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
@@ -8,8 +9,8 @@ import net.minecraftforge.fml.config.ModConfig;
|
||||
//From https://github.com/McJty/TutorialV3/blob/1.19/src/main/java/com/example/tutorialv3/setup/Config.java
|
||||
public class Config {
|
||||
public static void register() {
|
||||
registerServerConfigs();
|
||||
//registerCommonConfigs();
|
||||
//registerServerConfigs();
|
||||
registerCommonConfigs();
|
||||
//registerClientConfigs();
|
||||
}
|
||||
private static void registerClientConfigs() {
|
||||
@@ -19,12 +20,13 @@ public class Config {
|
||||
|
||||
private static void registerCommonConfigs() {
|
||||
ForgeConfigSpec.Builder COMMON_BUILDER = new ForgeConfigSpec.Builder();
|
||||
TradingStationConfig.registerCommonConfig(COMMON_BUILDER);
|
||||
PoweredTradingStationConfig.registerCommonConfig(COMMON_BUILDER);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, COMMON_BUILDER.build());
|
||||
}
|
||||
|
||||
private static void registerServerConfigs() {
|
||||
ForgeConfigSpec.Builder SERVER_BUILDER = new ForgeConfigSpec.Builder();
|
||||
TradingStationConfig.registerServerConfig(SERVER_BUILDER);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_BUILDER.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.oierbravo.trading_station.registrate;
|
||||
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockRenderer;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlock;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlockEntity;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationMenu;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationScreen;
|
||||
import com.tterrag.registrate.util.entry.BlockEntityEntry;
|
||||
import com.tterrag.registrate.util.entry.BlockEntry;
|
||||
import com.tterrag.registrate.util.entry.MenuEntry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraftforge.client.model.generators.ConfiguredModel;
|
||||
|
||||
public class MechanicalTradingStationRegistrate {
|
||||
/*public static final BlockEntry<PoweredTradingStationBlock> POWERED_TRADING_STATION_BLOCK = TradingStation.registrate()
|
||||
.block("powered_trading_station", PoweredTradingStationBlock::new)
|
||||
.lang("Powered Trading Station")
|
||||
.blockstate((ctx, prov) ->
|
||||
prov.getVariantBuilder(ctx.getEntry()).forAllStates(state -> {
|
||||
String modelFileName = "trading_station:block/powered_trading_station";
|
||||
if(state.getValue(BlockStateProperties.POWERED))
|
||||
modelFileName += "_powered";
|
||||
return ConfiguredModel.builder().modelFile(prov.models().getExistingFile(ResourceLocation.tryParse(modelFileName)))
|
||||
.rotationY(((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot() + 180) % 360).build();
|
||||
|
||||
})
|
||||
)
|
||||
.simpleItem()
|
||||
.blockEntity(PoweredTradingStationBlockEntity::new)
|
||||
.build()
|
||||
.register();
|
||||
|
||||
public static final BlockEntityEntry<PoweredTradingStationBlockEntity> POWERED_TRADING_STATION_BLOCK_ENTITY = TradingStation.registrate()
|
||||
.blockEntity("powered_trading_station", PoweredTradingStationBlockEntity::new)
|
||||
.validBlocks(POWERED_TRADING_STATION_BLOCK)
|
||||
.renderer(() -> TradingStationBlockRenderer::new)
|
||||
.register();
|
||||
|
||||
public static final MenuEntry<PoweredTradingStationMenu> POWERED_TRADING_STATION_MENU = TradingStation.registrate()
|
||||
.menu("powered_trading_station", PoweredTradingStationMenu::factory, () -> PoweredTradingStationScreen::new)
|
||||
.register();*/
|
||||
public static void register() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.oierbravo.trading_station.registrate;
|
||||
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockRenderer;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlockEntity;
|
||||
import com.tterrag.registrate.util.entry.BlockEntityEntry;
|
||||
|
||||
public class ModBlockEntities {
|
||||
public static final BlockEntityEntry<TradingStationBlockEntity> TRADING_STATION = TradingStation.registrate()
|
||||
.blockEntity("trading_station", TradingStationBlockEntity::new)
|
||||
.validBlocks(ModBlocks.TRADING_STATION)
|
||||
.renderer(() -> TradingStationBlockRenderer::new)
|
||||
.register();
|
||||
|
||||
public static final BlockEntityEntry<PoweredTradingStationBlockEntity> POWERED_TRADING_STATION = TradingStation.registrate()
|
||||
.blockEntity("powered_trading_station", PoweredTradingStationBlockEntity::new)
|
||||
.validBlocks(ModBlocks.POWERED_TRADING_STATION)
|
||||
.renderer(() -> TradingStationBlockRenderer::new)
|
||||
.register();
|
||||
public static void register() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,20 @@ package com.oierbravo.trading_station.registrate;
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class ModCreativeTab extends CreativeModeTab {
|
||||
public static ModCreativeTab MAIN;
|
||||
|
||||
|
||||
public ModCreativeTab() {
|
||||
super(TradingStation.DISPLAY_NAME);
|
||||
super(TradingStation.MODID);
|
||||
MAIN = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack makeIcon() {
|
||||
return new ItemStack(ModBlocks.TRADING_STATION.get());
|
||||
return new ItemStack(TradingStationRegistrate.TRADING_STATION_BLOCK.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.oierbravo.trading_station.registrate;
|
||||
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationMenu;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationScreen;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationMenu;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationScreen;
|
||||
import com.tterrag.registrate.util.entry.MenuEntry;
|
||||
|
||||
public class ModMenus {
|
||||
public static final MenuEntry<TradingStationMenu> TRADING_STATION = TradingStation.registrate()
|
||||
.menu("trading_station",TradingStationMenu::factory, () -> TradingStationScreen::new)
|
||||
.register();
|
||||
public static final MenuEntry<PoweredTradingStationMenu> POWERED_TRADING_STATION = TradingStation.registrate()
|
||||
.menu("powered_trading_station", PoweredTradingStationMenu::factory, () -> PoweredTradingStationScreen::new)
|
||||
.register();
|
||||
|
||||
public static void register() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ public class ModRecipes {
|
||||
|
||||
}
|
||||
public static void register(IEventBus eventBus) {
|
||||
|
||||
SERIALIZERS.register(eventBus);
|
||||
|
||||
RECIPE_TYPES.register(eventBus);
|
||||
|
||||
@@ -1,38 +1,21 @@
|
||||
package com.oierbravo.trading_station.registrate;
|
||||
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlock;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlock;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockEntity;
|
||||
import com.oierbravo.trading_station.content.trading_station.TradingStationBlockRenderer;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlock;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlockEntity;
|
||||
|
||||
import com.tterrag.registrate.Registrate;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationMenu;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationScreen;
|
||||
import com.tterrag.registrate.util.entry.BlockEntityEntry;
|
||||
import com.tterrag.registrate.util.entry.BlockEntry;
|
||||
import com.tterrag.registrate.util.entry.MenuEntry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraftforge.client.model.generators.ConfiguredModel;
|
||||
|
||||
public class ModBlocks {
|
||||
private static final Registrate REGISTRATE = TradingStation.registrate()
|
||||
.creativeModeTab(() -> ModCreativeTab.MAIN);
|
||||
public static final BlockEntry<TradingStationBlock> TRADING_STATION = TradingStation.registrate()
|
||||
.block("trading_station", TradingStationBlock::new)
|
||||
.lang("Trading Station")
|
||||
.blockstate((ctx, prov) ->
|
||||
prov.getVariantBuilder(ctx.getEntry()).forAllStates(state -> {
|
||||
String modelFileName = "trading_station:block/trading_station";
|
||||
if(state.getValue(BlockStateProperties.POWERED))
|
||||
modelFileName += "_powered";
|
||||
return ConfiguredModel.builder().modelFile(prov.models().getExistingFile(ResourceLocation.tryParse(modelFileName)))
|
||||
.rotationY(((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot() + 180) % 360).build();
|
||||
|
||||
})
|
||||
)
|
||||
.simpleItem()
|
||||
.blockEntity(TradingStationBlockEntity::new)
|
||||
.build()
|
||||
.register();
|
||||
public static final BlockEntry<PoweredTradingStationBlock> POWERED_TRADING_STATION = TradingStation.registrate()
|
||||
public class PoweredTradingStationRegistrate {
|
||||
public static final BlockEntry<PoweredTradingStationBlock> POWERED_TRADING_STATION_BLOCK = TradingStation.registrate()
|
||||
.block("powered_trading_station", PoweredTradingStationBlock::new)
|
||||
.lang("Powered Trading Station")
|
||||
.blockstate((ctx, prov) ->
|
||||
@@ -49,6 +32,16 @@ public class ModBlocks {
|
||||
.blockEntity(PoweredTradingStationBlockEntity::new)
|
||||
.build()
|
||||
.register();
|
||||
|
||||
public static final BlockEntityEntry<PoweredTradingStationBlockEntity> POWERED_TRADING_STATION_BLOCK_ENTITY = TradingStation.registrate()
|
||||
.blockEntity("powered_trading_station", PoweredTradingStationBlockEntity::new)
|
||||
.validBlocks(POWERED_TRADING_STATION_BLOCK)
|
||||
.renderer(() -> TradingStationBlockRenderer::new)
|
||||
.register();
|
||||
|
||||
public static final MenuEntry<PoweredTradingStationMenu> POWERED_TRADING_STATION_MENU = TradingStation.registrate()
|
||||
.menu("powered_trading_station", PoweredTradingStationMenu::factory, () -> PoweredTradingStationScreen::new)
|
||||
.register();
|
||||
public static void register() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.oierbravo.trading_station.registrate;
|
||||
|
||||
import com.oierbravo.trading_station.TradingStation;
|
||||
import com.oierbravo.trading_station.content.trading_station.*;
|
||||
import com.oierbravo.trading_station.content.trading_station.powered.PoweredTradingStationBlockEntity;
|
||||
import com.tterrag.registrate.Registrate;
|
||||
import com.tterrag.registrate.util.entry.BlockEntityEntry;
|
||||
import com.tterrag.registrate.util.entry.BlockEntry;
|
||||
import com.tterrag.registrate.util.entry.MenuEntry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraftforge.client.model.generators.ConfiguredModel;
|
||||
|
||||
public class TradingStationRegistrate {
|
||||
private static final Registrate REGISTRATE = TradingStation.registrate()
|
||||
.creativeModeTab(() -> ModCreativeTab.MAIN);
|
||||
|
||||
public static final BlockEntry<TradingStationBlock> TRADING_STATION_BLOCK = TradingStation.registrate()
|
||||
.block("trading_station", TradingStationBlock::new)
|
||||
.lang("Trading Station")
|
||||
.blockstate((ctx, prov) ->
|
||||
prov.getVariantBuilder(ctx.getEntry()).forAllStates(state -> {
|
||||
String modelFileName = "trading_station:block/trading_station";
|
||||
if(state.getValue(BlockStateProperties.POWERED))
|
||||
modelFileName += "_powered";
|
||||
return ConfiguredModel.builder().modelFile(prov.models().getExistingFile(ResourceLocation.tryParse(modelFileName)))
|
||||
.rotationY(((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot() + 180) % 360).build();
|
||||
|
||||
})
|
||||
)
|
||||
.simpleItem()
|
||||
.blockEntity(TradingStationBlockEntity::new)
|
||||
.build()
|
||||
.register();
|
||||
public static final BlockEntityEntry<TradingStationBlockEntity> TRADING_STATION_BLOCK_ENTITY = REGISTRATE
|
||||
.blockEntity("trading_station", TradingStationBlockEntity::new)
|
||||
.validBlocks(TRADING_STATION_BLOCK)
|
||||
.renderer(() -> TradingStationBlockRenderer::new)
|
||||
.register();
|
||||
|
||||
public static final MenuEntry<TradingStationMenu> TRADING_STATION_MENU = REGISTRATE
|
||||
.menu("trading_station",TradingStationMenu::factory, () -> TradingStationScreen::new)
|
||||
.register();
|
||||
|
||||
public static void register() {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user