Initial 1.19 port.
This commit is contained in:
parent
e59a9405d0
commit
96d675198f
139 changed files with 763 additions and 4940 deletions
|
@ -16,7 +16,6 @@ import net.minecraftforge.common.ForgeConfigSpec;
|
|||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import wile.engineersdecor.blocks.*;
|
||||
import wile.engineersdecor.libmc.blocks.SlabSliceBlock;
|
||||
import wile.engineersdecor.libmc.blocks.StandardBlocks;
|
||||
import wile.engineersdecor.libmc.blocks.VariantSlabBlock;
|
||||
import wile.engineersdecor.libmc.detail.Auxiliaries;
|
||||
import wile.engineersdecor.libmc.detail.OptionalRecipeCondition;
|
||||
|
@ -324,7 +323,7 @@ public class ModConfig
|
|||
{ return (block==null) || isOptedOut(block.asItem()); }
|
||||
|
||||
public static boolean isOptedOut(final @Nullable Item item)
|
||||
{ return (item!=null) && optouts_.contains(item.getRegistryName().getPath()); }
|
||||
{ return (item!=null) && optouts_.contains(Auxiliaries.getResourceLocation(item).getPath()); }
|
||||
|
||||
public static boolean withExperimental()
|
||||
{ return with_experimental_features_; }
|
||||
|
@ -385,14 +384,9 @@ public class ModConfig
|
|||
try {
|
||||
if(!with_experimental_features_) {
|
||||
if(block instanceof Auxiliaries.IExperimentalFeature) return true;
|
||||
if(ModContent.isExperimentalBlock(block)) return true;
|
||||
}
|
||||
// Hard IE dependent blocks
|
||||
if(!immersiveengineering_installed) {
|
||||
if((block instanceof StandardBlocks.IStandardBlock) && ((((StandardBlocks.IStandardBlock)block).config() & DecorBlock.CFG_HARD_IE_DEPENDENT)!=0)) return true;
|
||||
}
|
||||
// Force-include/exclude pattern matching
|
||||
final String rn = block.getRegistryName().getPath();
|
||||
final String rn = Auxiliaries.getResourceLocation(block).getPath();
|
||||
try {
|
||||
for(String e : includes) {
|
||||
if(rn.matches(e)) {
|
||||
|
@ -416,7 +410,7 @@ public class ModConfig
|
|||
}
|
||||
return false;
|
||||
}).forEach(
|
||||
e -> optouts.add(e.getRegistryName().getPath())
|
||||
e -> optouts.add(Auxiliaries.getResourceLocation(e).getPath())
|
||||
);
|
||||
optouts_ = optouts;
|
||||
}
|
||||
|
@ -439,8 +433,6 @@ public class ModConfig
|
|||
EdLadderBlock.on_config(SERVER.without_ladder_speed_boost.get());
|
||||
VariantSlabBlock.on_config(!SERVER.without_direct_slab_pickup.get());
|
||||
SlabSliceBlock.on_config(!SERVER.without_direct_slab_pickup.get());
|
||||
EdLabeledCrate.on_config(false);
|
||||
EdCraftingTable.on_config(SERVER.without_crafting_table_history.get(), false, SERVER.without_crafting_mouse_scrolling.get());
|
||||
EdFluidBarrel.on_config(12000, 1000);
|
||||
EdFluidFunnel.on_config(with_experimental_features_);
|
||||
EdPipeValve.on_config(SERVER.pipevalve_max_flowrate.get(), SERVER.pipevalve_redstone_gain.get());
|
||||
|
|
|
@ -15,7 +15,6 @@ package wile.engineersdecor;
|
|||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderers;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
|
@ -40,7 +39,6 @@ import net.minecraft.world.phys.shapes.Shapes;
|
|||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import wile.engineersdecor.blocks.*;
|
||||
import wile.engineersdecor.detail.ModRenderers;
|
||||
|
@ -292,10 +290,6 @@ public class ModContent
|
|||
StandardBlocks.CFG_DEFAULT,
|
||||
BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.3f, 8f).sound(SoundType.METAL).noOcclusion()
|
||||
));
|
||||
Registries.addBlock("treated_wood_ladder", ()->new EdLadderBlock(
|
||||
StandardBlocks.CFG_DEFAULT,
|
||||
BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.WOOD).strength(0.3f, 8f).sound(SoundType.WOOD).noOcclusion()
|
||||
));
|
||||
Registries.addBlock("iron_hatch", ()->new EdHatchBlock(
|
||||
StandardBlocks.CFG_LOOK_PLACEMENT,
|
||||
BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.3f, 2000f).sound(SoundType.METAL),
|
||||
|
@ -356,11 +350,6 @@ public class ModContent
|
|||
|
||||
// -------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Registries.addBlock("treated_wood_table", ()->new StandardBlocks.WaterLoggable(
|
||||
StandardBlocks.CFG_CUTOUT,
|
||||
BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.WOOD).strength(0.5f, 5f).sound(SoundType.WOOD).noOcclusion(),
|
||||
Auxiliaries.getPixeledAABB(1,0,1, 15,15.9,15)
|
||||
));
|
||||
Registries.addBlock("treated_wood_stool", ()->new EdChair.ChairBlock(
|
||||
StandardBlocks.CFG_CUTOUT|StandardBlocks.CFG_HORIZIONTAL|StandardBlocks.CFG_LOOK_PLACEMENT,
|
||||
BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.WOOD).strength(0.5f, 5f).sound(SoundType.WOOD).noOcclusion(),
|
||||
|
@ -371,16 +360,6 @@ public class ModContent
|
|||
Auxiliaries.getPixeledAABB(7,0,4, 9,1,12),
|
||||
}
|
||||
));
|
||||
Registries.addBlock("treated_wood_windowsill", ()->new StandardBlocks.DirectedWaterLoggable(
|
||||
StandardBlocks.CFG_CUTOUT|StandardBlocks.CFG_HORIZIONTAL|StandardBlocks.CFG_FACING_PLACEMENT|StandardBlocks.CFG_AI_PASSABLE,
|
||||
BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.WOOD).strength(0.5f, 5f).sound(SoundType.WOOD).noOcclusion(),
|
||||
Auxiliaries.getPixeledAABB(0.5,15,10.5, 15.5,16,16)
|
||||
));
|
||||
Registries.addBlock("treated_wood_broad_windowsill", ()->new StandardBlocks.DirectedWaterLoggable(
|
||||
StandardBlocks.CFG_CUTOUT|StandardBlocks.CFG_HORIZIONTAL|StandardBlocks.CFG_FACING_PLACEMENT,
|
||||
BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.WOOD).strength(0.5f, 5f).sound(SoundType.WOOD).noOcclusion(),
|
||||
Auxiliaries.getPixeledAABB(0,14.5,4, 16,16,16)
|
||||
));
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -432,11 +411,6 @@ public class ModContent
|
|||
|
||||
// -------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Registries.addBlock("treated_wood_window", ()->new EdWindowBlock(
|
||||
StandardBlocks.CFG_LOOK_PLACEMENT,
|
||||
BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.WOOD).strength(0.5f, 8f).sound(SoundType.WOOD).noOcclusion(),
|
||||
Auxiliaries.getPixeledAABB(0,0,7, 16,16,9)
|
||||
));
|
||||
Registries.addBlock("steel_framed_window", ()->new EdWindowBlock(
|
||||
StandardBlocks.CFG_LOOK_PLACEMENT,
|
||||
BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.5f, 8f).sound(SoundType.METAL).noOcclusion(),
|
||||
|
@ -642,37 +616,9 @@ public class ModContent
|
|||
BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.WOOD).strength(0.2f, 1f).sound(SoundType.WOOD).noOcclusion(),
|
||||
Auxiliaries.getPixeledAABB(2,2,15.6, 14,14,16)
|
||||
));
|
||||
Registries.addBlock("sign_factoryarea", ()->new StandardBlocks.DirectedWaterLoggable(
|
||||
StandardBlocks.CFG_CUTOUT|StandardBlocks.CFG_FACING_PLACEMENT|StandardBlocks.CFG_HORIZIONTAL|StandardBlocks.CFG_AI_PASSABLE,
|
||||
BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.WOOD).strength(0.2f, 1f).sound(SoundType.WOOD).noOcclusion(),
|
||||
Auxiliaries.getPixeledAABB(2,2,15.6, 14,14,16)
|
||||
));
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Registries.addBlock("labeled_crate",
|
||||
()->new EdLabeledCrate.LabeledCrateBlock(
|
||||
StandardBlocks.CFG_HORIZIONTAL|StandardBlocks.CFG_LOOK_PLACEMENT|StandardBlocks.CFG_OPPOSITE_PLACEMENT,
|
||||
BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.WOOD).strength(0.3f, 32f).sound(SoundType.METAL).noOcclusion(),
|
||||
Auxiliaries.getPixeledAABB(0,0,0, 16,16,16)
|
||||
),
|
||||
EdLabeledCrate.LabeledCrateTileEntity::new,
|
||||
EdLabeledCrate.LabeledCrateContainer::new
|
||||
);
|
||||
Registries.addBlock("metal_crafting_table",
|
||||
()->new EdCraftingTable.CraftingTableBlock(
|
||||
StandardBlocks.CFG_CUTOUT|StandardBlocks.CFG_HORIZIONTAL|StandardBlocks.CFG_LOOK_PLACEMENT|StandardBlocks.CFG_OPPOSITE_PLACEMENT,
|
||||
BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.3f, 12f).sound(SoundType.METAL).noOcclusion(),
|
||||
new AABB[]{
|
||||
Auxiliaries.getPixeledAABB(0,15,0, 16,16,16),
|
||||
Auxiliaries.getPixeledAABB(1, 0,1, 15,16,15)
|
||||
}
|
||||
),
|
||||
EdCraftingTable.CraftingTableTileEntity::new,
|
||||
EdCraftingTable.CraftingTableUiContainer::new
|
||||
//MenuScreens.register(CT_TREATED_WOOD_CRAFTING_TABLE, EdCraftingTable.CraftingTableGui::new);
|
||||
);
|
||||
|
||||
Registries.addBlock("small_lab_furnace",
|
||||
()->new EdFurnace.FurnaceBlock(
|
||||
StandardBlocks.CFG_CUTOUT|StandardBlocks.CFG_HORIZIONTAL|StandardBlocks.CFG_LOOK_PLACEMENT|StandardBlocks.CFG_OPPOSITE_PLACEMENT,
|
||||
|
@ -902,6 +848,7 @@ public class ModContent
|
|||
Auxiliaries.getPixeledAABB(2,15,0, 14,16,16),
|
||||
}
|
||||
),
|
||||
EdFluidBarrel.FluidBarrelItem::new,
|
||||
EdFluidBarrel.FluidBarrelTileEntity::new
|
||||
);
|
||||
Registries.addBlock("small_fluid_funnel",
|
||||
|
@ -919,35 +866,6 @@ public class ModContent
|
|||
|
||||
// -------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
if(Auxiliaries.isModLoaded("immersiveengineeringharddependent")) {
|
||||
//Registries.addBlock("halfslab_treated_wood", ()->new SlabSliceBlock(
|
||||
// StandardBlocks.CFG_CUTOUT|DecorBlock.CFG_HARD_IE_DEPENDENT,
|
||||
// BlockBehaviour.Properties.of(Material.WOOD, MaterialColor.WOOD).strength(0.3f, 4f).sound(SoundType.WOOD).noOcclusion()
|
||||
//));
|
||||
//Registries.addBlock("halfslab_sheetmetal_iron", ()->new SlabSliceBlock(
|
||||
// StandardBlocks.CFG_CUTOUT|DecorBlock.CFG_HARD_IE_DEPENDENT,
|
||||
// BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.3f, 8f).sound(SoundType.METAL).noOcclusion()
|
||||
//));
|
||||
//Registries.addBlock("halfslab_sheetmetal_steel", ()->new SlabSliceBlock(
|
||||
// StandardBlocks.CFG_CUTOUT|DecorBlock.CFG_HARD_IE_DEPENDENT,
|
||||
// BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.3f, 8f).sound(SoundType.METAL).noOcclusion()
|
||||
//));
|
||||
//Registries.addBlock("halfslab_sheetmetal_copper", ()->new SlabSliceBlock(
|
||||
// StandardBlocks.CFG_CUTOUT|DecorBlock.CFG_HARD_IE_DEPENDENT,
|
||||
// BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.3f, 8f).sound(SoundType.METAL).noOcclusion()
|
||||
//));
|
||||
//Registries.addBlock("halfslab_sheetmetal_gold", ()->new SlabSliceBlock(
|
||||
// StandardBlocks.CFG_CUTOUT|DecorBlock.CFG_HARD_IE_DEPENDENT,
|
||||
// BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.3f, 8f).sound(SoundType.METAL).noOcclusion()
|
||||
//));
|
||||
//Registries.addBlock("halfslab_sheetmetal_aluminum", ()->new SlabSliceBlock(
|
||||
// StandardBlocks.CFG_CUTOUT|DecorBlock.CFG_HARD_IE_DEPENDENT,
|
||||
// BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.3f, 8f).sound(SoundType.METAL).noOcclusion()
|
||||
//));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Registries.addBlock("test_block",
|
||||
()->new EdTestBlock.TestBlock(
|
||||
StandardBlocks.CFG_LOOK_PLACEMENT,
|
||||
|
@ -994,16 +912,15 @@ public class ModContent
|
|||
public static BlockEntityType<?> getBlockEntityTypeOfBlock(String block_name)
|
||||
{ return Registries.getBlockEntityTypeOfBlock(block_name); }
|
||||
|
||||
public static BlockEntityType<?> getBlockEntityTypeOfBlock(Block block)
|
||||
{ return Registries.getBlockEntityTypeOfBlock(block); }
|
||||
|
||||
public static EntityType<?> getEntityType(String name)
|
||||
{ return Registries.getEntityType(name); }
|
||||
|
||||
public static MenuType<?> getMenuType(String block_name)
|
||||
{ return Registries.getMenuTypeOfBlock(block_name); }
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean isExperimentalBlock(Block block)
|
||||
{ return (block instanceof StandardBlocks.IStandardBlock) && (((((StandardBlocks.IStandardBlock)block).config() & DecorBlock.CFG_EXPERIMENTAL))!=0); }
|
||||
|
||||
@Nonnull
|
||||
public static List<Block> getRegisteredBlocks()
|
||||
{ return Registries.getRegisteredBlocks(); }
|
||||
|
@ -1016,31 +933,10 @@ public class ModContent
|
|||
// Initialisation events
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static void registerBlocks(final RegistryEvent.Register<Block> event)
|
||||
{
|
||||
final boolean ie_available = Auxiliaries.isModLoaded("immersiveengineering");
|
||||
if(ie_available) Auxiliaries.logInfo("Immersive Engineering also installed ...");
|
||||
Registries.onBlockRegistry((rl, block)->event.getRegistry().register(block));
|
||||
}
|
||||
|
||||
public static void registerItems(final RegistryEvent.Register<Item> event)
|
||||
{ Registries.onItemRegistry((rl, item)->event.getRegistry().register(item)); }
|
||||
|
||||
public static void registerBlockEntityTypes(final RegistryEvent.Register<BlockEntityType<?>> event)
|
||||
{ Registries.onBlockEntityRegistry((rl, tet)->event.getRegistry().register(tet)); }
|
||||
|
||||
public static void registerEntityTypes(final RegistryEvent.Register<EntityType<?>> event)
|
||||
{ Registries.onEntityRegistry((rl, et)->event.getRegistry().register(et)); }
|
||||
|
||||
public static void registerMenuTypes(final RegistryEvent.Register<MenuType<?>> event)
|
||||
{ Registries.onMenuTypeRegistry((rl, ct)->event.getRegistry().register(ct)); }
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void registerMenuGuis(final FMLClientSetupEvent event)
|
||||
{
|
||||
MenuScreens.register((MenuType<EdCraftingTable.CraftingTableUiContainer>)Registries.getMenuTypeOfBlock("metal_crafting_table"), EdCraftingTable.CraftingTableGui::new);
|
||||
MenuScreens.register((MenuType<EdLabeledCrate.LabeledCrateContainer>)Registries.getMenuTypeOfBlock("labeled_crate"), EdLabeledCrate.LabeledCrateGui::new);
|
||||
MenuScreens.register((MenuType<EdDropper.DropperUiContainer>)Registries.getMenuTypeOfBlock("factory_dropper"), EdDropper.DropperGui::new);
|
||||
MenuScreens.register((MenuType<EdPlacer.PlacerContainer>)Registries.getMenuTypeOfBlock("factory_placer"), EdPlacer.PlacerGui::new);
|
||||
MenuScreens.register((MenuType<EdHopper.HopperContainer>)Registries.getMenuTypeOfBlock("factory_hopper"), EdHopper.HopperGui::new);
|
||||
|
@ -1053,8 +949,6 @@ public class ModContent
|
|||
@SuppressWarnings("unchecked")
|
||||
public static void registerBlockEntityRenderers(final FMLClientSetupEvent event)
|
||||
{
|
||||
BlockEntityRenderers.register((BlockEntityType<EdCraftingTable.CraftingTableTileEntity>)Registries.getBlockEntityTypeOfBlock("metal_crafting_table"), wile.engineersdecor.detail.ModRenderers.CraftingTableTer::new);
|
||||
BlockEntityRenderers.register((BlockEntityType<EdLabeledCrate.LabeledCrateTileEntity>)Registries.getBlockEntityTypeOfBlock("labeled_crate"), wile.engineersdecor.detail.ModRenderers.DecorLabeledCrateTer::new);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
package wile.engineersdecor;
|
||||
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
|
@ -17,8 +11,7 @@ import net.minecraftforge.fml.event.config.ModConfigEvent;
|
|||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import wile.engineersdecor.blocks.EdLadderBlock;
|
||||
import wile.engineersdecor.libmc.detail.Auxiliaries;
|
||||
import wile.engineersdecor.libmc.detail.OptionalRecipeCondition;
|
||||
|
@ -31,13 +24,13 @@ public class ModEngineersDecor
|
|||
public static final String MODID = "engineersdecor";
|
||||
public static final String MODNAME = "Engineer's Decor";
|
||||
public static final int VERSION_DATAFIXER = 0;
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Logger LOGGER = com.mojang.logging.LogUtils.getLogger();
|
||||
|
||||
public ModEngineersDecor()
|
||||
{
|
||||
Auxiliaries.init(MODID, LOGGER, ModConfig::getServerConfig);
|
||||
Auxiliaries.logGitVersion(MODNAME);
|
||||
Registries.init(MODID, "sign_decor");
|
||||
Registries.init(MODID, "sign_decor", (reg)->reg.register(FMLJavaModLoadingContext.get().getModEventBus()));
|
||||
ModContent.init(MODID);
|
||||
OptionalRecipeCondition.init(MODID, LOGGER);
|
||||
ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.SERVER, ModConfig.SERVER_CONFIG_SPEC);
|
||||
|
@ -68,26 +61,6 @@ public class ModEngineersDecor
|
|||
@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class ForgeEvents
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void onRegisterBlocks(final RegistryEvent.Register<Block> event)
|
||||
{ ModContent.registerBlocks(event); }
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegisterItems(final RegistryEvent.Register<Item> event)
|
||||
{ ModContent.registerItems(event); }
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegisterBlockEntityTypes(final RegistryEvent.Register<BlockEntityType<?>> event)
|
||||
{ ModContent.registerBlockEntityTypes(event); }
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegisterEntityTypes(final RegistryEvent.Register<EntityType<?>> event)
|
||||
{ ModContent.registerEntityTypes(event); }
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegisterMenuTypes(final RegistryEvent.Register<MenuType<?>> event)
|
||||
{ ModContent.registerMenuTypes(event); }
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onConfigLoad(final ModConfigEvent.Loading event)
|
||||
{ ModConfig.apply(); }
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* @file DecorBlock.java
|
||||
* @author Stefan Wilhelm (wile)
|
||||
* @copyright (C) 2020 Stefan Wilhelm
|
||||
* @license MIT (see https://opensource.org/licenses/MIT)
|
||||
*
|
||||
* Common functionality class for decor blocks.
|
||||
* Mainly needed for:
|
||||
* - MC block defaults.
|
||||
* - Tooltip functionality
|
||||
* - Model initialisation
|
||||
*/
|
||||
package wile.engineersdecor.blocks;
|
||||
|
||||
import wile.engineersdecor.libmc.blocks.StandardBlocks;
|
||||
|
||||
public class DecorBlock
|
||||
{
|
||||
public static final long CFG_DEFAULT = StandardBlocks.CFG_DEFAULT;
|
||||
public static final long CFG_CUTOUT = StandardBlocks.CFG_CUTOUT;
|
||||
public static final long CFG_MIPPED = StandardBlocks.CFG_MIPPED;
|
||||
public static final long CFG_TRANSLUCENT = StandardBlocks.CFG_TRANSLUCENT;
|
||||
public static final long CFG_WATERLOGGABLE = StandardBlocks.CFG_WATERLOGGABLE;
|
||||
public static final long CFG_HORIZIONTAL = StandardBlocks.CFG_HORIZIONTAL;
|
||||
public static final long CFG_LOOK_PLACEMENT = StandardBlocks.CFG_LOOK_PLACEMENT;
|
||||
public static final long CFG_FACING_PLACEMENT = StandardBlocks.CFG_FACING_PLACEMENT;
|
||||
public static final long CFG_OPPOSITE_PLACEMENT = StandardBlocks.CFG_OPPOSITE_PLACEMENT;
|
||||
public static final long CFG_FLIP_PLACEMENT_IF_SAME = StandardBlocks.CFG_FLIP_PLACEMENT_IF_SAME;
|
||||
public static final long CFG_FLIP_PLACEMENT_SHIFTCLICK = StandardBlocks.CFG_FLIP_PLACEMENT_SHIFTCLICK;
|
||||
public static final long CFG_STRICT_CONNECTIONS = StandardBlocks.CFG_STRICT_CONNECTIONS;
|
||||
public static final long CFG_AI_PASSABLE = StandardBlocks.CFG_AI_PASSABLE;
|
||||
public static final long CFG_HARD_IE_DEPENDENT = 0x8000000000000000L;
|
||||
@Deprecated public static final long CFG_EXPERIMENTAL = 0x4000000000000000L;
|
||||
}
|
|
@ -12,7 +12,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
|
@ -93,10 +92,6 @@ public class EdBreaker
|
|||
public BreakerBlock(long config, BlockBehaviour.Properties builder, final AABB[] unrotatedAABBs)
|
||||
{ super(config, builder, unrotatedAABBs); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -195,7 +190,7 @@ public class EdBreaker
|
|||
private final LazyOptional<IEnergyStorage> energy_handler_ = battery_.createEnergyHandler();
|
||||
|
||||
public BreakerTileEntity(BlockPos pos, BlockState state)
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state); }
|
||||
|
||||
public void block_updated()
|
||||
{ if(tick_timer_ > 2) tick_timer_ = 2; }
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
@ -35,8 +36,6 @@ import wile.engineersdecor.ModContent;
|
|||
import wile.engineersdecor.libmc.blocks.StandardBlocks;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
|
||||
public class EdChair
|
||||
|
@ -81,7 +80,7 @@ public class EdChair
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void tick(BlockState state, ServerLevel world, BlockPos pos, Random rnd)
|
||||
public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource rnd)
|
||||
{
|
||||
if((!sitting_enabled) || (sitting_probability < 1e-6)) return;
|
||||
final List<Mob> entities = world.getEntitiesOfClass(Mob.class, new AABB(pos).inflate(2,1,2).expandTowards(0,1,0), e->true);
|
||||
|
|
|
@ -11,6 +11,7 @@ package wile.engineersdecor.blocks;
|
|||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@ -30,7 +31,6 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
|||
import wile.engineersdecor.libmc.blocks.StandardBlocks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Random;
|
||||
|
||||
public class EdChimneyBlock extends StandardBlocks.Cutout
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ public class EdChimneyBlock extends StandardBlocks.Cutout
|
|||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void animateTick(BlockState state, Level world, BlockPos pos, Random rnd)
|
||||
public void animateTick(BlockState state, Level world, BlockPos pos, RandomSource rnd)
|
||||
{
|
||||
if(state.getBlock() != this) return;
|
||||
final int p = state.getValue(POWER);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -13,9 +13,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -90,10 +87,6 @@ public class EdDropper
|
|||
public DropperBlock(long config, BlockBehaviour.Properties builder, final AABB unrotatedAABB)
|
||||
{ super(config, builder, unrotatedAABB); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -232,7 +225,7 @@ public class EdDropper
|
|||
protected LazyOptional<? extends IItemHandler> item_handler_ = Inventories.MappedItemHandler.createGenericHandler(storage_slot_range_);
|
||||
|
||||
public DropperTileEntity(BlockPos pos, BlockState state)
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); reset_rtstate(); }
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state); reset_rtstate(); }
|
||||
|
||||
public CompoundTag clear_getnbt()
|
||||
{
|
||||
|
@ -312,7 +305,7 @@ public class EdDropper
|
|||
|
||||
@Override
|
||||
public Component getName()
|
||||
{ final Block block=getBlockState().getBlock(); return new TextComponent((block!=null) ? block.getDescriptionId() : "Factory dropper"); }
|
||||
{ return Auxiliaries.localizable(getBlockState().getBlock().getDescriptionId()); }
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
|
@ -738,7 +731,7 @@ public class EdDropper
|
|||
public void onClientPacketReceived(int windowId, Player player, CompoundTag nbt)
|
||||
{
|
||||
if(!(inventory_ instanceof Inventories.StorageInventory)) return;
|
||||
if(!(((Inventories.StorageInventory)inventory_).getTileEntity() instanceof final DropperTileEntity te)) return;
|
||||
if(!(((Inventories.StorageInventory)inventory_).getBlockEntity() instanceof final DropperTileEntity te)) return;
|
||||
if(nbt.contains("action")) {
|
||||
boolean changed = false;
|
||||
final int slotId = nbt.contains("slot") ? nbt.getInt("slot") : -1;
|
||||
|
@ -786,18 +779,18 @@ public class EdDropper
|
|||
{
|
||||
super.init();
|
||||
{
|
||||
final Block block = ModContent.getBlock(getMenu().getType().getRegistryName().getPath().replaceAll("^ct_",""));
|
||||
final Block block = ModContent.getBlock(Auxiliaries.getResourceLocation(getMenu().getType()).getPath().replaceAll("^ct_",""));
|
||||
final String prefix = block.getDescriptionId() + ".tooltips.";
|
||||
final int x0 = getGuiLeft(), y0 = getGuiTop();
|
||||
tooltip_.init(
|
||||
new TipRange(x0+130, y0+10, 12, 25, new TranslatableComponent(prefix + "velocity")),
|
||||
new TipRange(x0+145, y0+10, 25, 25, new TranslatableComponent(prefix + "direction")),
|
||||
new TipRange(x0+129, y0+40, 44, 10, new TranslatableComponent(prefix + "dropcount")),
|
||||
new TipRange(x0+129, y0+50, 44, 10, new TranslatableComponent(prefix + "period")),
|
||||
new TipRange(x0+114, y0+51, 9, 9, new TranslatableComponent(prefix + "rssignal")),
|
||||
new TipRange(x0+162, y0+66, 7, 9, new TranslatableComponent(prefix + "triggermode")),
|
||||
new TipRange(x0+132, y0+66, 9, 9, new TranslatableComponent(prefix + "filtergate")),
|
||||
new TipRange(x0+148, y0+66, 9, 9, new TranslatableComponent(prefix + "externgate"))
|
||||
new TipRange(x0+130, y0+10, 12, 25, Component.translatable(prefix + "velocity")),
|
||||
new TipRange(x0+145, y0+10, 25, 25, Component.translatable(prefix + "direction")),
|
||||
new TipRange(x0+129, y0+40, 44, 10, Component.translatable(prefix + "dropcount")),
|
||||
new TipRange(x0+129, y0+50, 44, 10, Component.translatable(prefix + "period")),
|
||||
new TipRange(x0+114, y0+51, 9, 9, Component.translatable(prefix + "rssignal")),
|
||||
new TipRange(x0+162, y0+66, 7, 9, Component.translatable(prefix + "triggermode")),
|
||||
new TipRange(x0+132, y0+66, 9, 9, Component.translatable(prefix + "filtergate")),
|
||||
new TipRange(x0+148, y0+66, 9, 9, Component.translatable(prefix + "externgate"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.*;
|
||||
import net.minecraft.world.entity.ExperienceOrb;
|
||||
|
@ -60,12 +57,9 @@ import wile.engineersdecor.ModConfig;
|
|||
import wile.engineersdecor.ModContent;
|
||||
import wile.engineersdecor.libmc.blocks.StandardBlocks;
|
||||
import wile.engineersdecor.libmc.blocks.StandardEntityBlocks;
|
||||
import wile.engineersdecor.libmc.detail.Crafting;
|
||||
import wile.engineersdecor.libmc.detail.Inventories;
|
||||
import wile.engineersdecor.libmc.detail.*;
|
||||
import wile.engineersdecor.libmc.detail.Inventories.MappedItemHandler;
|
||||
import wile.engineersdecor.libmc.detail.Inventories.StorageInventory;
|
||||
import wile.engineersdecor.libmc.detail.Networking;
|
||||
import wile.engineersdecor.libmc.detail.RfEnergy;
|
||||
import wile.engineersdecor.libmc.detail.TooltipDisplay.TipRange;
|
||||
import wile.engineersdecor.libmc.ui.Guis;
|
||||
|
||||
|
@ -91,10 +85,6 @@ public class EdElectricalFurnace
|
|||
public ElectricalFurnaceBlock(long config, BlockBehaviour.Properties builder, final AABB[] unrotatedAABBs)
|
||||
{ super(config, builder, unrotatedAABBs); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -251,7 +241,7 @@ public class EdElectricalFurnace
|
|||
|
||||
public ElectricalFurnaceTileEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state);
|
||||
inventory_ = new StorageInventory(this, NUM_OF_SLOTS) {
|
||||
@Override
|
||||
public void setItem(int index, ItemStack stack)
|
||||
|
@ -353,7 +343,7 @@ public class EdElectricalFurnace
|
|||
|
||||
@Override
|
||||
public Component getName()
|
||||
{ final Block block=getBlockState().getBlock(); return new TextComponent((block!=null) ? block.getDescriptionId() : "Small electrical furnace"); }
|
||||
{ return Auxiliaries.localizable(getBlockState().getBlock().getDescriptionId()); }
|
||||
|
||||
@Override
|
||||
public Component getDisplayName()
|
||||
|
@ -727,7 +717,7 @@ public class EdElectricalFurnace
|
|||
{
|
||||
stack.onCraftedBy(player_.level, player_, removeCount);
|
||||
if((!player_.level.isClientSide()) && (inventory_ instanceof StorageInventory) &&
|
||||
(((StorageInventory)inventory_).getTileEntity()) instanceof final ElectricalFurnaceTileEntity te) {
|
||||
(((StorageInventory)inventory_).getBlockEntity()) instanceof final ElectricalFurnaceTileEntity te) {
|
||||
int xp = te.consumeSmeltingExperience(stack);
|
||||
while(xp > 0) {
|
||||
int k = ExperienceOrb.getExperienceValue(xp);
|
||||
|
@ -848,7 +838,7 @@ public class EdElectricalFurnace
|
|||
public void onClientPacketReceived(int windowId, Player player, CompoundTag nbt)
|
||||
{
|
||||
if(!(inventory_ instanceof StorageInventory)) return;
|
||||
if(!((((StorageInventory)inventory_).getTileEntity()) instanceof final ElectricalFurnaceTileEntity te)) return;
|
||||
if(!((((StorageInventory)inventory_).getBlockEntity()) instanceof final ElectricalFurnaceTileEntity te)) return;
|
||||
if(nbt.contains("speed")) te.speed_ = Mth.clamp(nbt.getInt("speed"), 0, ElectricalFurnaceTileEntity.MAX_SPEED_SETTING);
|
||||
te.setChanged();
|
||||
}
|
||||
|
@ -868,17 +858,17 @@ public class EdElectricalFurnace
|
|||
public void init()
|
||||
{
|
||||
super.init();
|
||||
final Block block = ModContent.getBlock(getMenu().getType().getRegistryName().getPath().replaceAll("^ct_",""));
|
||||
final Block block = ModContent.getBlock(Auxiliaries.getResourceLocation(getMenu().getType()).getPath().replaceAll("^ct_",""));
|
||||
final String prefix = block.getDescriptionId() + ".tooltips.";
|
||||
final int x0 = getGuiLeft(), y0 = getGuiTop();
|
||||
final Slot aux = menu.getSlot(ElectricalFurnaceTileEntity.SMELTING_AUX_SLOT_NO);
|
||||
tooltip_.init(
|
||||
new TipRange(x0+135, y0+50, 25, 25, new TranslatableComponent(prefix + "speed")),
|
||||
new TipRange(x0+aux.x, y0+aux.y, 16, 16, new TranslatableComponent(prefix + "auxslot")),
|
||||
new TipRange(x0+135, y0+50, 25, 25, Component.translatable(prefix + "speed")),
|
||||
new TipRange(x0+aux.x, y0+aux.y, 16, 16, Component.translatable(prefix + "auxslot")),
|
||||
new TipRange(x0+80, y0+55, 50, 14, ()->{
|
||||
final int soc = getMenu().field(1) * 100 / Math.max(getMenu().field(5), 1);
|
||||
final int consumption = getMenu().field(7);
|
||||
return new TranslatableComponent(prefix + "capacitors", soc, consumption);
|
||||
return Component.translatable(prefix + "capacitors", soc, consumption);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@ import net.minecraft.core.Direction;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
|
@ -88,7 +86,7 @@ public class EdFluidBarrel
|
|||
// Block
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static class FluidBarrelBlock extends StandardBlocks.DirectedWaterLoggable implements StandardEntityBlocks.IStandardEntityBlock<FluidBarrelTileEntity>, StandardBlocks.IBlockItemFactory
|
||||
public static class FluidBarrelBlock extends StandardBlocks.DirectedWaterLoggable implements StandardEntityBlocks.IStandardEntityBlock<FluidBarrelTileEntity>
|
||||
{
|
||||
public static final int FILL_LEVEL_MAX = 4;
|
||||
public static final IntegerProperty FILL_LEVEL = IntegerProperty.create("level", 0, FILL_LEVEL_MAX);
|
||||
|
@ -99,18 +97,10 @@ public class EdFluidBarrel
|
|||
registerDefaultState(super.defaultBlockState().setValue(FACING, Direction.UP).setValue(FILL_LEVEL, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
||||
@Override
|
||||
public BlockItem getBlockItem(Block block, Item.Properties builder)
|
||||
{ return new FluidBarrelItem(block, builder); }
|
||||
|
||||
@Override
|
||||
public boolean hasDynamicDropList()
|
||||
{ return true; }
|
||||
|
@ -141,7 +131,7 @@ public class EdFluidBarrel
|
|||
}
|
||||
FluidStack fs = FluidBarrelItem.getFluid(stack);
|
||||
if(!fs.isEmpty()) {
|
||||
tooltip.add(Auxiliaries.localizable(getDescriptionId()+".status.tip", Integer.toString(fs.getAmount()), Integer.toString(capacity_), new TranslatableComponent(fs.getTranslationKey())));
|
||||
tooltip.add(Auxiliaries.localizable(getDescriptionId()+".status.tip", Integer.toString(fs.getAmount()), Integer.toString(capacity_), Component.translatable(fs.getTranslationKey())));
|
||||
} else {
|
||||
tooltip.add(Auxiliaries.localizable(getDescriptionId()+".status.tip.empty", "0", Integer.toString(capacity_)));
|
||||
}
|
||||
|
@ -225,7 +215,7 @@ public class EdFluidBarrel
|
|||
private final LazyOptional<IFluidHandler> fluid_handler_ = tank_.createFluidHandler();
|
||||
|
||||
public FluidBarrelTileEntity(BlockPos pos, BlockState state)
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state); }
|
||||
|
||||
public void readnbt(CompoundTag nbt)
|
||||
{ tank_.load(nbt); }
|
||||
|
@ -251,7 +241,7 @@ public class EdFluidBarrel
|
|||
{
|
||||
int vol = tank_.getFluidAmount();
|
||||
int cap = tank_.getCapacity();
|
||||
String name = (new TranslatableComponent(tank_.getFluid().getTranslationKey())).getString();
|
||||
String name = (Component.translatable(tank_.getFluid().getTranslationKey())).getString();
|
||||
if((vol>0) && (cap>0)) {
|
||||
Overlay.show(player, Auxiliaries.localizable("block.engineersdecor.fluid_barrel.status", Integer.toString(vol), Integer.toString(cap), name));
|
||||
} else {
|
||||
|
|
|
@ -14,7 +14,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
@ -77,10 +76,6 @@ public class EdFluidFunnel
|
|||
public FluidFunnelBlock(long config, BlockBehaviour.Properties builder, final AABB[] unrotatedAABB)
|
||||
{ super(config, builder, unrotatedAABB); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -195,7 +190,7 @@ public class EdFluidFunnel
|
|||
private final LazyOptional<IFluidHandler> fluid_handler_ = tank_.createOutputFluidHandler();
|
||||
|
||||
public FluidFunnelTileEntity(BlockPos pos, BlockState state)
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state); }
|
||||
|
||||
public void readnbt(CompoundTag nbt)
|
||||
{
|
||||
|
|
|
@ -12,10 +12,10 @@ package wile.engineersdecor.blocks;
|
|||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
@ -57,7 +57,6 @@ import javax.annotation.Nonnull;
|
|||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class EdFreezer
|
||||
{
|
||||
|
@ -76,10 +75,6 @@ public class EdFreezer
|
|||
public FreezerBlock(long config, BlockBehaviour.Properties builder, final AABB unrotatedAABB)
|
||||
{ super(config, builder, unrotatedAABB); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -162,7 +157,7 @@ public class EdFreezer
|
|||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void animateTick(BlockState state, Level world, BlockPos pos, Random rnd)
|
||||
public void animateTick(BlockState state, Level world, BlockPos pos, RandomSource rnd)
|
||||
{}
|
||||
|
||||
@Nullable
|
||||
|
@ -207,7 +202,7 @@ public class EdFreezer
|
|||
}
|
||||
|
||||
public FreezerTileEntity(BlockPos pos, BlockState state)
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state); }
|
||||
|
||||
public int progress()
|
||||
{ return progress_; }
|
||||
|
|
|
@ -14,11 +14,11 @@ import net.minecraft.core.Direction;
|
|||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.*;
|
||||
import net.minecraft.world.entity.ExperienceOrb;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
@ -88,10 +88,6 @@ public class EdFurnace
|
|||
public FurnaceBlock(long config, BlockBehaviour.Properties properties, final AABB[] unrotatedAABB)
|
||||
{ super(config, properties, unrotatedAABB); registerDefaultState(super.defaultBlockState().setValue(LIT, false)); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -174,7 +170,7 @@ public class EdFurnace
|
|||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void animateTick(BlockState state, Level world, BlockPos pos, Random rnd)
|
||||
public void animateTick(BlockState state, Level world, BlockPos pos, RandomSource rnd)
|
||||
{
|
||||
if((state.getBlock()!=this) || (!state.getValue(LIT))) return;
|
||||
final double rv = rnd.nextDouble();
|
||||
|
@ -250,8 +246,8 @@ public class EdFurnace
|
|||
}
|
||||
}
|
||||
}
|
||||
ModConfig.log("Config lab furnace speed:" + (proc_speed_*100) + "%, efficiency:" + (proc_fuel_efficiency_*100) + "%, boost: " + (boost_energy_consumption/TICK_INTERVAL) + "rf/t.");
|
||||
ModConfig.log("Config lab furnace accepted heaters: " + accepted_heaters_.stream().map(item->item.getRegistryName().toString()).collect(Collectors.joining(",")) + ".");
|
||||
Auxiliaries.logInfo("Config lab furnace speed:" + (proc_speed_*100) + "%, efficiency:" + (proc_fuel_efficiency_*100) + "%, boost: " + (boost_energy_consumption/TICK_INTERVAL) + "rf/t.");
|
||||
Auxiliaries.logInfo("Config lab furnace accepted heaters: " + accepted_heaters_.stream().map(item->Auxiliaries.getResourceLocation(item).toString()).collect(Collectors.joining(",")) + ".");
|
||||
}
|
||||
|
||||
// DecorFurnaceTileEntity -----------------------------------------------------------------------------
|
||||
|
@ -276,7 +272,7 @@ public class EdFurnace
|
|||
|
||||
public FurnaceTileEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state);
|
||||
inventory_ = new StorageInventory(this, NUM_OF_SLOTS) {
|
||||
@Override
|
||||
public void setItem(int index, ItemStack stack)
|
||||
|
@ -404,7 +400,7 @@ public class EdFurnace
|
|||
|
||||
@Override
|
||||
public Component getName()
|
||||
{ final Block block=getBlockState().getBlock(); return new TextComponent((block!=null) ? block.getDescriptionId() : "Lab furnace"); }
|
||||
{ return Auxiliaries.localizable(getBlockState().getBlock().getDescriptionId()); }
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
|
@ -709,7 +705,7 @@ public class EdFurnace
|
|||
{
|
||||
stack.onCraftedBy(player_.level, player_, removeCount);
|
||||
if((!player_.level.isClientSide()) && (inventory_ instanceof StorageInventory) &&
|
||||
((((StorageInventory)inventory_).getTileEntity()) instanceof final FurnaceTileEntity te)
|
||||
((((StorageInventory)inventory_).getBlockEntity()) instanceof final FurnaceTileEntity te)
|
||||
) {
|
||||
int xp = te.consumeSmeltingExperience(stack);
|
||||
while(xp > 0) {
|
||||
|
|
|
@ -13,9 +13,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.*;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
@ -70,10 +67,6 @@ public class EdHopper
|
|||
public HopperBlock(long config, BlockBehaviour.Properties builder, final Supplier<ArrayList<VoxelShape>> shape_supplier)
|
||||
{ super(config, builder, shape_supplier); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -215,7 +208,7 @@ public class EdHopper
|
|||
|
||||
public HopperTileEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state);
|
||||
main_inventory_.setSlotChangeAction((slot,stack)->tick_timer_ = Math.min(tick_timer_, 8));
|
||||
}
|
||||
|
||||
|
@ -290,7 +283,7 @@ public class EdHopper
|
|||
|
||||
@Override
|
||||
public Component getName()
|
||||
{ final Block block=getBlockState().getBlock(); return new TextComponent((block!=null) ? block.getDescriptionId() : "Factory Hopper"); }
|
||||
{ return Auxiliaries.localizable(getBlockState().getBlock().getDescriptionId()); }
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
|
@ -717,7 +710,7 @@ public class EdHopper
|
|||
public void onClientPacketReceived(int windowId, Player player, CompoundTag nbt)
|
||||
{
|
||||
if(!(inventory_ instanceof Inventories.StorageInventory)) return;
|
||||
if(!((((((Inventories.StorageInventory)inventory_).getTileEntity())) instanceof final EdHopper.HopperTileEntity te))) return;
|
||||
if(!((((((Inventories.StorageInventory)inventory_).getBlockEntity())) instanceof final EdHopper.HopperTileEntity te))) return;
|
||||
if(nbt.contains("xsize")) te.transfer_count_ = Mth.clamp(nbt.getInt("xsize"), 1, HopperTileEntity.MAX_TRANSFER_COUNT);
|
||||
if(nbt.contains("period")) te.transfer_period_ = Mth.clamp(nbt.getInt("period"), 0, 100);
|
||||
if(nbt.contains("range")) te.collection_range_ = Mth.clamp(nbt.getInt("range"), 0, HopperTileEntity.MAX_COLLECTION_RANGE);
|
||||
|
@ -760,17 +753,17 @@ public class EdHopper
|
|||
{
|
||||
super.init();
|
||||
{
|
||||
final Block block = ModContent.getBlock(getMenu().getType().getRegistryName().getPath().replaceAll("^ct_",""));
|
||||
final Block block = ModContent.getBlock( Auxiliaries.getResourceLocation(getMenu().getType()).getPath().replaceAll("^ct_",""));
|
||||
final String prefix = block.getDescriptionId() + ".tooltips.";
|
||||
final int x0 = getGuiLeft(), y0 = getGuiTop();
|
||||
tooltip_.init(
|
||||
new TooltipDisplay.TipRange(x0+148, y0+22, 3, 3, new TranslatableComponent(prefix + "delayindicator")),
|
||||
new TooltipDisplay.TipRange(x0+130, y0+ 9, 40, 10, new TranslatableComponent(prefix + "range")),
|
||||
new TooltipDisplay.TipRange(x0+130, y0+22, 40, 10, new TranslatableComponent(prefix + "period")),
|
||||
new TooltipDisplay.TipRange(x0+130, y0+35, 40, 10, new TranslatableComponent(prefix + "count")),
|
||||
new TooltipDisplay.TipRange(x0+133, y0+49, 9, 9, new TranslatableComponent(prefix + "rssignal")),
|
||||
new TooltipDisplay.TipRange(x0+145, y0+49, 9, 9, new TranslatableComponent(prefix + "inversion")),
|
||||
new TooltipDisplay.TipRange(x0+159, y0+49, 9, 9, new TranslatableComponent(prefix + "triggermode"))
|
||||
new TooltipDisplay.TipRange(x0+148, y0+22, 3, 3, Component.translatable(prefix + "delayindicator")),
|
||||
new TooltipDisplay.TipRange(x0+130, y0+ 9, 40, 10, Component.translatable(prefix + "range")),
|
||||
new TooltipDisplay.TipRange(x0+130, y0+22, 40, 10, Component.translatable(prefix + "period")),
|
||||
new TooltipDisplay.TipRange(x0+130, y0+35, 40, 10, Component.translatable(prefix + "count")),
|
||||
new TooltipDisplay.TipRange(x0+133, y0+49, 9, 9, Component.translatable(prefix + "rssignal")),
|
||||
new TooltipDisplay.TipRange(x0+145, y0+49, 9, 9, Component.translatable(prefix + "inversion")),
|
||||
new TooltipDisplay.TipRange(x0+159, y0+49, 9, 9, Component.translatable(prefix + "triggermode"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class EdHorizontalSupportBlock extends StandardBlocks.WaterLoggable
|
|||
|
||||
public EdHorizontalSupportBlock(long config, BlockBehaviour.Properties builder, final AABB mainBeamAABB, final AABB eastBeamAABB, final AABB thinDownBeamAABB, final AABB thickDownBeamAABB)
|
||||
{
|
||||
super(config|DecorBlock.CFG_HORIZIONTAL, builder);
|
||||
super(config|StandardBlocks.CFG_HORIZIONTAL, builder);
|
||||
Map<BlockState, VoxelShape> aabbs = new HashMap<>();
|
||||
for(boolean eastwest:EASTWEST.getPossibleValues()) {
|
||||
for(boolean leftbeam:LEFTBEAM.getPossibleValues()) {
|
||||
|
|
|
@ -1,606 +0,0 @@
|
|||
/*
|
||||
* @file EdLabeledCrate.java
|
||||
* @author Stefan Wilhelm (wile)
|
||||
* @copyright (C) 2020 Stefan Wilhelm
|
||||
* @license MIT (see https://opensource.org/licenses/MIT)
|
||||
*
|
||||
* Storage crate with a content hint.
|
||||
*/
|
||||
package wile.engineersdecor.blocks;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.world.*;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.*;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.PushReaction;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import wile.engineersdecor.ModConfig;
|
||||
import wile.engineersdecor.ModContent;
|
||||
import wile.engineersdecor.libmc.blocks.StandardBlocks;
|
||||
import wile.engineersdecor.libmc.blocks.StandardEntityBlocks;
|
||||
import wile.engineersdecor.libmc.detail.Auxiliaries;
|
||||
import wile.engineersdecor.libmc.detail.Inventories;
|
||||
import wile.engineersdecor.libmc.detail.Networking;
|
||||
import wile.engineersdecor.libmc.detail.RsSignals;
|
||||
import wile.engineersdecor.libmc.ui.Guis;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
|
||||
public class EdLabeledCrate
|
||||
{
|
||||
private static boolean with_gui_mouse_handling = true;
|
||||
private static final HashSet<Item> unstorable_containers = new HashSet<>();
|
||||
|
||||
public static void on_config(boolean without_gui_mouse_handling)
|
||||
{
|
||||
with_gui_mouse_handling = !without_gui_mouse_handling;
|
||||
// Currently no config, using a tag for this small feature may be uselessly stressing the registry.
|
||||
unstorable_containers.clear();
|
||||
unstorable_containers.add(ModContent.getBlock("labeled_crate").asItem());
|
||||
unstorable_containers.add(Items.SHULKER_BOX);
|
||||
ModConfig.log("Config crate: unstorable:" + unstorable_containers.stream().map(e->e.getRegistryName().toString()).collect(Collectors.joining(",")));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
// Block
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static class LabeledCrateBlock extends StandardBlocks.Horizontal implements StandardEntityBlocks.IStandardEntityBlock<LabeledCrateTileEntity>
|
||||
{
|
||||
public LabeledCrateBlock(long config, BlockBehaviour.Properties builder, final AABB unrotatedAABB)
|
||||
{ super(config, builder, unrotatedAABB); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return false; }
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean hasAnalogOutputSignal(BlockState state)
|
||||
{ return true; }
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getAnalogOutputSignal(BlockState blockState, Level world, BlockPos pos)
|
||||
{ return (!(world.getBlockEntity(pos) instanceof LabeledCrateTileEntity te)) ? 0 : RsSignals.fromContainer(te.main_inventory_); }
|
||||
|
||||
@Override
|
||||
public boolean shouldCheckWeakPower(BlockState state, LevelReader world, BlockPos pos, Direction side)
|
||||
{ return false; }
|
||||
|
||||
@Override
|
||||
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack)
|
||||
{
|
||||
if((world.isClientSide) || (!stack.hasTag())) return;
|
||||
final BlockEntity te = world.getBlockEntity(pos);
|
||||
if(!(te instanceof LabeledCrateTileEntity)) return;
|
||||
final CompoundTag nbt = stack.getTag();
|
||||
if(nbt.contains("tedata")) {
|
||||
CompoundTag te_nbt = nbt.getCompound("tedata");
|
||||
if(!te_nbt.isEmpty()) ((LabeledCrateTileEntity)te).readnbt(te_nbt);
|
||||
}
|
||||
((LabeledCrateTileEntity)te).setCustomName(Auxiliaries.getItemLabel(stack));
|
||||
te.setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDynamicDropList()
|
||||
{ return true; }
|
||||
|
||||
@Override
|
||||
public List<ItemStack> dropList(BlockState state, Level world, final BlockEntity te, boolean explosion)
|
||||
{
|
||||
final List<ItemStack> stacks = new ArrayList<>();
|
||||
if(world.isClientSide()) return stacks;
|
||||
if(!(te instanceof LabeledCrateTileEntity)) return stacks;
|
||||
if(!explosion) {
|
||||
ItemStack stack = new ItemStack(this, 1);
|
||||
CompoundTag te_nbt = ((LabeledCrateTileEntity)te).getnbt();
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
if(!te_nbt.isEmpty()) nbt.put("tedata", te_nbt);
|
||||
if(!nbt.isEmpty()) stack.setTag(nbt);
|
||||
Auxiliaries.setItemLabel(stack, ((LabeledCrateTileEntity)te).getCustomName());
|
||||
stacks.add(stack);
|
||||
} else {
|
||||
for(ItemStack stack: ((LabeledCrateTileEntity)te).main_inventory_) stacks.add(stack);
|
||||
((LabeledCrateTileEntity)te).getnbt();
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult rayTraceResult)
|
||||
{ return useOpenGui(state, world, pos, player); }
|
||||
|
||||
@Override
|
||||
public PushReaction getPistonPushReaction(BlockState state)
|
||||
{ return PushReaction.BLOCK; }
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void appendHoverText(final ItemStack stack, @Nullable BlockGetter world, List<Component> tooltip, TooltipFlag flag)
|
||||
{
|
||||
if(!Auxiliaries.Tooltip.extendedTipCondition() || Auxiliaries.Tooltip.helpCondition()) {
|
||||
super.appendHoverText(stack, world, tooltip, flag);
|
||||
return;
|
||||
}
|
||||
ItemStack frameStack = ItemStack.EMPTY;
|
||||
int num_used_slots = 0, total_items = 0;
|
||||
String stats = "";
|
||||
if(stack.hasTag() && stack.getTag().contains("tedata")) {
|
||||
final CompoundTag nbt = stack.getTag().getCompound("tedata");
|
||||
if(nbt.contains("Items")) {
|
||||
final NonNullList<ItemStack> all_items = Inventories.readNbtStacks(nbt, LabeledCrateTileEntity.NUM_OF_SLOTS);
|
||||
frameStack = all_items.get(LabeledCrateTileEntity.ITEMFRAME_SLOTNO);
|
||||
all_items.set(LabeledCrateTileEntity.ITEMFRAME_SLOTNO, ItemStack.EMPTY);
|
||||
Map<Item,Integer> item_map = new HashMap<>();
|
||||
for(ItemStack e:all_items) { // ok, the whole stream map collector seems to be actually slower than a simple loop.
|
||||
if(!e.isEmpty()) {
|
||||
item_map.put(e.getItem(), item_map.getOrDefault(e.getItem(), 0) + e.getCount());
|
||||
++num_used_slots;
|
||||
total_items += e.getCount();
|
||||
}
|
||||
}
|
||||
List<Tuple<String,Integer>> itmes = new ArrayList<>();
|
||||
for(Map.Entry<Item,Integer> e:item_map.entrySet()) itmes.add(new Tuple<>(e.getKey().getDescriptionId(), e.getValue()));
|
||||
itmes.sort((a,b)->b.getB()-a.getB());
|
||||
boolean dotdotdot = false;
|
||||
if(itmes.size() > 8) { itmes.subList(8, itmes.size()).clear(); dotdotdot = true; }
|
||||
stats = itmes.stream().map(e->Auxiliaries.localize(e.getA())).collect(Collectors.joining(", "));
|
||||
if(dotdotdot) stats += "...";
|
||||
}
|
||||
}
|
||||
int num_free_slots = LabeledCrateTileEntity.ITEMFRAME_SLOTNO - num_used_slots;
|
||||
String[] lines = Auxiliaries.localize(getDescriptionId()+".tip",
|
||||
(frameStack.isEmpty() ? (new TextComponent("-/-")) : (new TranslatableComponent(frameStack.getDescriptionId()))),
|
||||
num_used_slots,
|
||||
num_free_slots,
|
||||
total_items,
|
||||
stats).split("\n");
|
||||
for(String line:lines) {
|
||||
tooltip.add(new TextComponent(line.trim()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
// Tile entity
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static class LabeledCrateTileEntity extends StandardEntityBlocks.StandardBlockEntity implements MenuProvider, Nameable, Networking.IPacketTileNotifyReceiver
|
||||
{
|
||||
public static final int NUM_OF_FIELDS = 1;
|
||||
public static final int NUM_OF_SLOTS = 55;
|
||||
public static final int NUM_OF_STORAGE_SLOTS = 54;
|
||||
public static final int NUM_OF_STORAGE_ROWS = 6;
|
||||
public static final int ITEMFRAME_SLOTNO = NUM_OF_STORAGE_SLOTS;
|
||||
|
||||
private final Inventories.StorageInventory main_inventory_ = new Inventories.StorageInventory(this, NUM_OF_SLOTS, 1);
|
||||
private final Inventories.InventoryRange storage_range_ = new Inventories.InventoryRange(main_inventory_, 0, NUM_OF_STORAGE_SLOTS, NUM_OF_STORAGE_ROWS);
|
||||
private final LazyOptional<IItemHandler> item_handler_;
|
||||
|
||||
private @Nullable Component custom_name_;
|
||||
|
||||
public LabeledCrateTileEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
|
||||
main_inventory_.setCloseAction((player)->Networking.PacketTileNotifyServerToClient.sendToPlayers(this, writenbt(new CompoundTag())));
|
||||
main_inventory_.setSlotChangeAction((index,stack)->{
|
||||
if(index==ITEMFRAME_SLOTNO) Networking.PacketTileNotifyServerToClient.sendToPlayers(this, writenbt(new CompoundTag()));
|
||||
});
|
||||
item_handler_ = Inventories.MappedItemHandler.createGenericHandler(storage_range_,
|
||||
(slot,stack)->(slot!=ITEMFRAME_SLOTNO),
|
||||
(slot,stack)->(slot!=ITEMFRAME_SLOTNO),
|
||||
IntStream.range(0, NUM_OF_STORAGE_SLOTS).boxed().collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
public CompoundTag getnbt()
|
||||
{ return writenbt(new CompoundTag()); }
|
||||
|
||||
public CompoundTag readnbt(CompoundTag nbt)
|
||||
{
|
||||
if(nbt.contains("name", Tag.TAG_STRING)) custom_name_ = Auxiliaries.unserializeTextComponent(nbt.getString("name"));
|
||||
main_inventory_.load(nbt);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
protected CompoundTag writenbt(CompoundTag nbt)
|
||||
{
|
||||
if(custom_name_ != null) nbt.putString("name", Auxiliaries.serializeTextComponent(custom_name_));
|
||||
if(!main_inventory_.isEmpty()) main_inventory_.save(nbt);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public ItemStack getItemFrameStack()
|
||||
{ return main_inventory_.getItem(ITEMFRAME_SLOTNO); }
|
||||
|
||||
protected static boolean inacceptable(ItemStack stack)
|
||||
{ return (stack.hasTag() && (!stack.getTag().isEmpty()) && (unstorable_containers.contains(stack.getItem()))); }
|
||||
|
||||
// IPacketTileNotifyReceiver ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void onServerPacketReceived(CompoundTag nbt)
|
||||
{ readnbt(nbt); }
|
||||
|
||||
// Capability export ----------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable Direction facing)
|
||||
{
|
||||
if(capability==CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return item_handler_.cast();
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
// BlockEntity ------------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag nbt)
|
||||
{ super.load(nbt); readnbt(nbt); }
|
||||
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag nbt)
|
||||
{ super.saveAdditional(nbt); writenbt(nbt); }
|
||||
|
||||
@Override
|
||||
public void setRemoved()
|
||||
{
|
||||
super.setRemoved();
|
||||
item_handler_.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getUpdateTag()
|
||||
{ CompoundTag nbt = super.getUpdateTag(); writenbt(nbt); return nbt; }
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ClientboundBlockEntityDataPacket getUpdatePacket()
|
||||
{ return ClientboundBlockEntityDataPacket.create(this); }
|
||||
|
||||
@Override
|
||||
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) // on client
|
||||
{ super.onDataPacket(net, pkt); if(pkt.getTag() != null) { readnbt(pkt.getTag()); } }
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag(CompoundTag tag) // on client
|
||||
{ load(tag); }
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public double getViewDistance()
|
||||
{ return 1600; }
|
||||
|
||||
// INameable ---------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Component getName()
|
||||
{
|
||||
if(custom_name_ != null) return custom_name_;
|
||||
final Block block = getBlockState().getBlock();
|
||||
if(block!=null) return new TranslatableComponent(block.getDescriptionId());
|
||||
return new TextComponent("Labeled Crate");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Component getCustomName()
|
||||
{ return custom_name_; }
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{ return (custom_name_ != null); }
|
||||
|
||||
public void setCustomName(Component name)
|
||||
{ custom_name_ = name; }
|
||||
|
||||
// IContainerProvider ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Component getDisplayName()
|
||||
{ return Nameable.super.getDisplayName(); }
|
||||
|
||||
@Override
|
||||
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player)
|
||||
{ return new LabeledCrateContainer(id, inventory, main_inventory_, ContainerLevelAccess.create(level, worldPosition), fields); }
|
||||
|
||||
// Fields -----------------------------------------------------------------------------------------------
|
||||
|
||||
protected final ContainerData fields = new ContainerData()
|
||||
{
|
||||
@Override
|
||||
public int getCount()
|
||||
{ return LabeledCrateTileEntity.NUM_OF_FIELDS; }
|
||||
|
||||
@Override
|
||||
public int get(int id)
|
||||
{
|
||||
return switch (id) {
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public void set(int id, int value)
|
||||
{
|
||||
switch(id) {
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
// Container
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static class LabeledCrateContainer extends AbstractContainerMenu implements Networking.INetworkSynchronisableContainer
|
||||
{
|
||||
protected static final String QUICK_MOVE_ALL = "quick-move-all";
|
||||
protected static final String INCREASE_STACK = "increase-stack";
|
||||
protected static final String DECREASE_STACK = "decrease-stack";
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
protected static class StorageSlot extends Slot
|
||||
{
|
||||
StorageSlot(Container inventory, int index, int x, int y)
|
||||
{ super(inventory, index, x, y); }
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize()
|
||||
{ return 64; }
|
||||
|
||||
@Override
|
||||
public boolean mayPlace(ItemStack stack)
|
||||
{ return !LabeledCrateTileEntity.inacceptable(stack); }
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
private static final int PLAYER_INV_START_SLOTNO = LabeledCrateTileEntity.NUM_OF_SLOTS;
|
||||
private static final int NUM_OF_CONTAINER_SLOTS = LabeledCrateTileEntity.NUM_OF_SLOTS + 36;
|
||||
protected static final int STORAGE_SLOT_BEGIN = 0;
|
||||
protected static final int STORAGE_SLOT_END = LabeledCrateTileEntity.ITEMFRAME_SLOTNO;
|
||||
protected static final int PLAYER_SLOT_BEGIN = LabeledCrateTileEntity.NUM_OF_SLOTS;
|
||||
protected static final int PLAYER_SLOT_END = LabeledCrateTileEntity.NUM_OF_SLOTS+36;
|
||||
protected final Player player_;
|
||||
protected final Container inventory_;
|
||||
protected final ContainerLevelAccess wpc_;
|
||||
private final ContainerData fields_;
|
||||
private final Inventories.InventoryRange player_inventory_range_;
|
||||
private final Inventories.InventoryRange block_storage_range_;
|
||||
private final Inventories.InventoryRange frame_slot_range_;
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
public int field(int index) { return fields_.get(index); }
|
||||
public Player player() { return player_ ; }
|
||||
public Container inventory() { return inventory_ ; }
|
||||
public Level world() { return player_.level; }
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public LabeledCrateContainer(int cid, Inventory player_inventory)
|
||||
{ this(cid, player_inventory, new SimpleContainer(LabeledCrateTileEntity.NUM_OF_SLOTS), ContainerLevelAccess.NULL, new SimpleContainerData(LabeledCrateTileEntity.NUM_OF_FIELDS)); }
|
||||
|
||||
private LabeledCrateContainer(int cid, Inventory player_inventory, Container block_inventory, ContainerLevelAccess wpc, ContainerData fields)
|
||||
{
|
||||
super(ModContent.getMenuType("labeled_crate"), cid); // @todo: class mapping
|
||||
player_ = player_inventory.player;
|
||||
inventory_ = block_inventory;
|
||||
wpc_ = wpc;
|
||||
wpc_.execute((w,p)->inventory_.startOpen(player_));
|
||||
fields_ = fields;
|
||||
block_storage_range_ = new Inventories.InventoryRange(inventory_, 0, LabeledCrateTileEntity.ITEMFRAME_SLOTNO);
|
||||
player_inventory_range_ = new Inventories.InventoryRange(player_inventory, 0, 36);
|
||||
frame_slot_range_ = new Inventories.InventoryRange(inventory_, 54, 1);
|
||||
int i=-1;
|
||||
// storage slots (stacks 0 to 53)
|
||||
for(int y=0; y<6; ++y) {
|
||||
for(int x=0; x<9; ++x) {
|
||||
int xpos = 28+x*18, ypos = 10+y*18;
|
||||
addSlot(new StorageSlot(inventory_, ++i, xpos, ypos));
|
||||
}
|
||||
}
|
||||
// picture frame slot (54)
|
||||
addSlot(new Slot(frame_slot_range_, 0, 191, 100) { @Override public int getMaxStackSize(){return 1;} });
|
||||
// player slots
|
||||
for(int x=0; x<9; ++x) {
|
||||
addSlot(new Slot(player_inventory, x, 28+x*18, 183)); // player slots: 0..8
|
||||
}
|
||||
for(int y=0; y<3; ++y) {
|
||||
for(int x=0; x<9; ++x) {
|
||||
addSlot(new Slot(player_inventory, x+y*9+9, 28+x*18, 125+y*18)); // player slots: 9..35
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player)
|
||||
{ return inventory_.stillValid(player); }
|
||||
|
||||
@Override
|
||||
public boolean canTakeItemForPickAll(ItemStack stack, Slot slot)
|
||||
{ return (slot.getMaxStackSize() > 1); }
|
||||
|
||||
@Override
|
||||
public void removed(Player player)
|
||||
{
|
||||
super.removed(player);
|
||||
inventory_.stopOpen(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player player, int index)
|
||||
{
|
||||
Slot slot = getSlot(index);
|
||||
if((slot==null) || (!slot.hasItem())) return ItemStack.EMPTY;
|
||||
ItemStack slot_stack = slot.getItem();
|
||||
ItemStack transferred = slot_stack.copy();
|
||||
if((index>=0) && (index<PLAYER_INV_START_SLOTNO)) {
|
||||
// Crate slots
|
||||
if(!moveItemStackTo(slot_stack, PLAYER_INV_START_SLOTNO, PLAYER_INV_START_SLOTNO+36, false)) return ItemStack.EMPTY;
|
||||
} else if((index >= PLAYER_INV_START_SLOTNO) && (index <= PLAYER_INV_START_SLOTNO+36)) {
|
||||
// Player slot
|
||||
if(!moveItemStackTo(slot_stack, 0, PLAYER_INV_START_SLOTNO-1, false)) return ItemStack.EMPTY;
|
||||
} else {
|
||||
// Invalid slot
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if(slot_stack.isEmpty()) {
|
||||
slot.set(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.setChanged();
|
||||
}
|
||||
if(slot_stack.getCount() == transferred.getCount()) return ItemStack.EMPTY;
|
||||
slot.onTake(player, slot_stack);
|
||||
return transferred;
|
||||
}
|
||||
|
||||
// Container client/server synchronisation --------------------------------------------------
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void onGuiAction(String message, CompoundTag nbt)
|
||||
{
|
||||
nbt.putString("action", message);
|
||||
Networking.PacketContainerSyncClientToServer.sendToServer(containerId, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServerPacketReceived(int windowId, CompoundTag nbt)
|
||||
{}
|
||||
|
||||
@Override
|
||||
public void onClientPacketReceived(int windowId, Player player, CompoundTag nbt)
|
||||
{
|
||||
if(!nbt.contains("action")) return;
|
||||
boolean changed = false;
|
||||
final int slotId = nbt.contains("slot") ? nbt.getInt("slot") : -1;
|
||||
switch (nbt.getString("action")) {
|
||||
case QUICK_MOVE_ALL -> {
|
||||
if((slotId >= STORAGE_SLOT_BEGIN) && (slotId < STORAGE_SLOT_END) && (getSlot(slotId).hasItem())) {
|
||||
changed = block_storage_range_.move(getSlot(slotId).getSlotIndex(), player_inventory_range_, true, false, true, true);
|
||||
} else if ((slotId >= PLAYER_SLOT_BEGIN) && (slotId < PLAYER_SLOT_END) && (getSlot(slotId).hasItem())) {
|
||||
changed = player_inventory_range_.move(getSlot(slotId).getSlotIndex(), block_storage_range_, true, false, false, true);
|
||||
}
|
||||
}
|
||||
case INCREASE_STACK -> {}
|
||||
case DECREASE_STACK -> {}
|
||||
}
|
||||
if(changed) {
|
||||
inventory_.setChanged();
|
||||
player.getInventory().setChanged();
|
||||
broadcastChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
// GUI
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class LabeledCrateGui extends Guis.ContainerGui<LabeledCrateContainer>
|
||||
{
|
||||
public LabeledCrateGui(LabeledCrateContainer container, Inventory player_inventory, Component title)
|
||||
{
|
||||
super(container, player_inventory, title,"textures/gui/labeled_crate_gui.png", 213, 206);
|
||||
titleLabelX = 23;
|
||||
titleLabelY = -10;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels(PoseStack mx, int x, int y)
|
||||
{
|
||||
font.draw(mx, title, (float)titleLabelX+1, (float)titleLabelY+1, 0x303030);
|
||||
font.draw(mx, title, (float)titleLabelX, (float)titleLabelY, 0x707070);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
protected void action(String message)
|
||||
{ action(message, new CompoundTag()); }
|
||||
|
||||
protected void action(String message, CompoundTag nbt)
|
||||
{ getMenu().onGuiAction(message, nbt); }
|
||||
|
||||
@Override
|
||||
protected void slotClicked(Slot slot, int slotId, int button, ClickType type)
|
||||
{
|
||||
if(!with_gui_mouse_handling) {
|
||||
super.slotClicked(slot, slotId, button, type);
|
||||
} else if((type == ClickType.QUICK_MOVE) && (slot!=null) && slot.hasItem() && Auxiliaries.isShiftDown() && Auxiliaries.isCtrlDown()) {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
nbt.putInt("slot", slotId);
|
||||
action(LabeledCrateContainer.QUICK_MOVE_ALL, nbt);
|
||||
} else {
|
||||
super.slotClicked(slot, slotId, button, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double wheel_inc)
|
||||
{
|
||||
if(!with_gui_mouse_handling) return super.mouseScrolled(mouseX, mouseY, wheel_inc);
|
||||
final Slot slot = getSlotUnderMouse();
|
||||
if((slot==null) || (!slot.hasItem())) return true;
|
||||
final int count = slot.getItem().getCount();
|
||||
int limit = (Auxiliaries.isShiftDown() ? 2 : 1) * (Auxiliaries.isCtrlDown() ? 4 : 1);
|
||||
if(wheel_inc > 0.1) {
|
||||
if(count > 0) {
|
||||
if((count < slot.getItem().getMaxStackSize()) && (count < slot.getMaxStackSize())) {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
nbt.putInt("slot", slot.index);
|
||||
if(limit > 1) nbt.putInt("limit", limit);
|
||||
action(LabeledCrateContainer.INCREASE_STACK, nbt);
|
||||
}
|
||||
}
|
||||
} else if(wheel_inc < -0.1) {
|
||||
if(count > 0) {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
nbt.putInt("slot", slot.index);
|
||||
if(limit > 1) nbt.putInt("limit", limit);
|
||||
action(LabeledCrateContainer.DECREASE_STACK, nbt);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -12,7 +12,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
|
@ -120,10 +119,6 @@ public class EdMilker
|
|||
cshapes.replaceAll((state,shape)->Shapes.create(Auxiliaries.getPixeledAABB(0,0,0, 16,24,16)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -220,7 +215,7 @@ public class EdMilker
|
|||
|
||||
public MilkerTileEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state);
|
||||
tank_ = new Fluidics.Tank(TANK_CAPACITY, 0, BUCKET_SIZE, fs->fs.isFluidEqual(milk_fluid_));
|
||||
fluid_handler_ = tank_.createOutputFluidHandler();
|
||||
battery_ = new RfEnergy.Battery(MAX_ENERGY_BUFFER, MAX_ENERGY_TRANSFER, 0);
|
||||
|
@ -274,7 +269,7 @@ public class EdMilker
|
|||
|
||||
public void state_message(Player player)
|
||||
{
|
||||
Component rf = (energy_consumption_ <= 0) ? (new TextComponent("")) : (Auxiliaries.localizable("block.engineersdecor.small_milking_machine.status.rf", battery_.getEnergyStored()));
|
||||
Component rf = (energy_consumption_ <= 0) ? (Component.empty()) : (Auxiliaries.localizable("block.engineersdecor.small_milking_machine.status.rf", battery_.getEnergyStored()));
|
||||
Overlay.show(player, Auxiliaries.localizable("block.engineersdecor.small_milking_machine.status", tank_.getFluidAmount(), rf));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.resources.ResourceLocation;
|
|||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
@ -81,10 +82,6 @@ public class EdMineralSmelter
|
|||
public MineralSmelterBlock(long config, BlockBehaviour.Properties builder, final AABB unrotatedAABB)
|
||||
{ super(config, builder, unrotatedAABB); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -189,7 +186,7 @@ public class EdMineralSmelter
|
|||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void animateTick(BlockState state, Level world, BlockPos pos, Random rnd)
|
||||
public void animateTick(BlockState state, Level world, BlockPos pos, RandomSource rnd)
|
||||
{
|
||||
if(state.getBlock()!=this) return;
|
||||
ParticleOptions particle = ParticleTypes.SMOKE;
|
||||
|
@ -272,7 +269,7 @@ public class EdMineralSmelter
|
|||
|
||||
public MineralSmelterTileEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state);
|
||||
main_inventory_ = (new Inventories.StorageInventory(this, NUM_OF_SLOTS, 1)).setStackLimit(1);
|
||||
item_handler_ = Inventories.MappedItemHandler.createGenericHandler(
|
||||
main_inventory_,
|
||||
|
|
|
@ -11,7 +11,6 @@ package wile.engineersdecor.blocks;
|
|||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -76,10 +75,6 @@ public class EdPipeValve
|
|||
public PipeValveBlock(long config, int valve_config, BlockBehaviour.Properties builder, final AABB[] unrotatedAABB)
|
||||
{ super(config, builder, unrotatedAABB); this.valve_config = valve_config; }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state)
|
||||
|
|
|
@ -13,9 +13,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
|
@ -57,7 +54,6 @@ import net.minecraftforge.fluids.IFluidBlock;
|
|||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import wile.engineersdecor.ModContent;
|
||||
import wile.engineersdecor.ModEngineersDecor;
|
||||
import wile.engineersdecor.libmc.blocks.StandardBlocks;
|
||||
import wile.engineersdecor.libmc.blocks.StandardEntityBlocks;
|
||||
import wile.engineersdecor.libmc.detail.*;
|
||||
|
@ -83,10 +79,6 @@ public class EdPlacer
|
|||
public PlacerBlock(long config, BlockBehaviour.Properties builder, final AABB[] unrotatedAABB)
|
||||
{ super(config, builder, unrotatedAABB); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -206,7 +198,7 @@ public class EdPlacer
|
|||
|
||||
public PlacerTileEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state);
|
||||
item_handler_ = Inventories.MappedItemHandler.createGenericHandler(inventory_,
|
||||
(stack, slot) -> true,
|
||||
(stack, slot) -> true
|
||||
|
@ -278,7 +270,7 @@ public class EdPlacer
|
|||
|
||||
@Override
|
||||
public Component getName()
|
||||
{ final Block block=getBlockState().getBlock(); return new TextComponent((block!=null) ? block.getDescriptionId() : "Factory placer"); }
|
||||
{ return Auxiliaries.localizable(getBlockState().getBlock().getDescriptionId()); }
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
|
@ -383,7 +375,7 @@ public class EdPlacer
|
|||
Block block = Block.byItem(item);
|
||||
if(block == Blocks.AIR) {
|
||||
if(item != null) {
|
||||
if(debug_) Auxiliaries.logInfo("Placer spit: No block for item " + item.getRegistryName().toString());
|
||||
if(debug_) Auxiliaries.logInfo("Placer spit: No block for item " + Auxiliaries.getResourceLocation(item));
|
||||
return spit_out(facing); // Item not accepted
|
||||
}
|
||||
} else if(block instanceof IPlantable) {
|
||||
|
@ -459,7 +451,7 @@ public class EdPlacer
|
|||
}
|
||||
BlockState placement_state = (use_context==null) ? (block.defaultBlockState()) : (block.getStateForPlacement(use_context));
|
||||
if(placement_state == null) {
|
||||
if(debug_) Auxiliaries.logInfo("Placer spit: No valid placement state for item " + item.getRegistryName().toString());
|
||||
if(debug_) Auxiliaries.logInfo("Placer spit: No valid placement state for item " + Auxiliaries.getResourceLocation(item));
|
||||
return spit_out(facing);
|
||||
} else if((use_context!=null) && (item instanceof BlockItem)) {
|
||||
if(((BlockItem)item).place(use_context) != InteractionResult.FAIL) {
|
||||
|
@ -641,7 +633,7 @@ public class EdPlacer
|
|||
public void onClientPacketReceived(int windowId, Player player, CompoundTag nbt)
|
||||
{
|
||||
if(!(inventory_ instanceof Inventories.StorageInventory)) return;
|
||||
if(!((((Inventories.StorageInventory)inventory_).getTileEntity()) instanceof PlacerTileEntity te)) return;
|
||||
if(!((((Inventories.StorageInventory)inventory_).getBlockEntity()) instanceof PlacerTileEntity te)) return;
|
||||
if(nbt.contains("action")) {
|
||||
final int slotId = nbt.contains("slot") ? nbt.getInt("slot") : -1;
|
||||
boolean changed = false;
|
||||
|
@ -683,13 +675,13 @@ public class EdPlacer
|
|||
{
|
||||
super.init();
|
||||
{
|
||||
final Block block = ModContent.getBlock(getMenu().getType().getRegistryName().getPath().replaceAll("^ct_",""));
|
||||
final Block block = ModContent.getBlock(Auxiliaries.getResourceLocation(getMenu().getType()).getPath().replaceAll("^ct_",""));
|
||||
final String prefix = block.getDescriptionId() + ".tooltips.";
|
||||
final int x0 = getGuiLeft(), y0 = getGuiTop();
|
||||
tooltip_.init(
|
||||
new TooltipDisplay.TipRange(x0+133, y0+49, 9, 9, new TranslatableComponent(prefix + "rssignal")),
|
||||
new TooltipDisplay.TipRange(x0+145, y0+49, 9, 9, new TranslatableComponent(prefix + "inversion")),
|
||||
new TooltipDisplay.TipRange(x0+159, y0+49, 9, 9, new TranslatableComponent(prefix + "triggermode"))
|
||||
new TooltipDisplay.TipRange(x0+133, y0+49, 9, 9, Component.translatable(prefix + "rssignal")),
|
||||
new TooltipDisplay.TipRange(x0+145, y0+49, 9, 9, Component.translatable(prefix + "inversion")),
|
||||
new TooltipDisplay.TipRange(x0+159, y0+49, 9, 9, Component.translatable(prefix + "triggermode"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ package wile.engineersdecor.blocks;
|
|||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
@ -76,10 +75,6 @@ public class EdSolarPanel
|
|||
registerDefaultState(super.defaultBlockState().setValue(EXPOSITION, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -125,7 +120,7 @@ public class EdSolarPanel
|
|||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public SolarPanelTileEntity(BlockPos pos, BlockState state)
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state); }
|
||||
|
||||
public void readnbt(CompoundTag nbt, boolean update_packet)
|
||||
{ battery_.load(nbt); }
|
||||
|
|
|
@ -46,7 +46,7 @@ public class EdStraightPoleBlock extends StandardBlocks.DirectedWaterLoggable
|
|||
{
|
||||
Direction facing = context.getClickedFace();
|
||||
BlockState state = super.getStateForPlacement(context).setValue(FACING, facing);
|
||||
if((config & DecorBlock.CFG_FLIP_PLACEMENT_IF_SAME) != 0) {
|
||||
if((config & StandardBlocks.CFG_FLIP_PLACEMENT_IF_SAME) != 0) {
|
||||
Level world = context.getLevel();
|
||||
BlockPos pos = context.getClickedPos();
|
||||
if(world.getBlockState(pos.relative(facing.getOpposite())).getBlock() instanceof EdStraightPoleBlock) {
|
||||
|
|
|
@ -11,8 +11,7 @@ package wile.engineersdecor.blocks;
|
|||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@ -62,10 +61,6 @@ public class EdTestBlock
|
|||
public TestBlock(long config, BlockBehaviour.Properties builder, final AABB unrotatedAABB)
|
||||
{ super(config, builder, unrotatedAABB); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -136,7 +131,7 @@ public class EdTestBlock
|
|||
|
||||
public TestTileEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
|
||||
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state);
|
||||
battery_ = new RfEnergy.Battery((int)1e9, (int)1e9, 0, 0);
|
||||
energy_handler_ = battery_.createEnergyHandler();
|
||||
tank_ = new Fluidics.Tank((int)1e9);
|
||||
|
@ -223,7 +218,7 @@ public class EdTestBlock
|
|||
if(items_received_total > 0) msgs.add("+" + items_received_total + "items");
|
||||
if(items_inserted_total > 0) msgs.add("-" + items_inserted_total + "items");
|
||||
if(msgs.isEmpty()) msgs.add("Nothing transferred yet.");
|
||||
Overlay.show(player, new TextComponent(String.join(" | ", msgs)), 1000);
|
||||
Overlay.show(player, Component.literal(String.join(" | ", msgs)), 1000);
|
||||
return true;
|
||||
} else if(paused) {
|
||||
if(!getFillFluid(held).isEmpty()) {
|
||||
|
@ -237,19 +232,19 @@ public class EdTestBlock
|
|||
liq_fill_stack.setAmount(amount);
|
||||
}
|
||||
if(liq_fill_stack.isEmpty()) {
|
||||
Overlay.show(player, new TextComponent("Fluid fill: none"), 1000);
|
||||
Overlay.show(player, Component.literal("Fluid fill: none"), 1000);
|
||||
} else {
|
||||
Overlay.show(player, new TextComponent("Fluid fill: " + liq_fill_stack.getAmount() + "mb/t of " + liq_fill_stack.getFluid().getRegistryName()), 1000);
|
||||
Overlay.show(player, Component.literal("Fluid fill: " + liq_fill_stack.getAmount() + "mb/t of " + Auxiliaries.getResourceLocation(liq_fill_stack.getFluid())), 1000);
|
||||
}
|
||||
} else if(held.getItem() == Items.REDSTONE) {
|
||||
rf_feed_setting = (rf_feed_setting<<1) & 0x00fffff0;
|
||||
if(rf_feed_setting == 0) rf_feed_setting = 0x10;
|
||||
Overlay.show(player, new TextComponent("RF feed rate: " + rf_feed_setting + "rf/t"), 1000);
|
||||
Overlay.show(player, Component.literal("RF feed rate: " + rf_feed_setting + "rf/t"), 1000);
|
||||
} else {
|
||||
BlockState adjacent_state = level.getBlockState(worldPosition.relative(block_facing));
|
||||
if(adjacent_state.getBlock()==Blocks.HOPPER || adjacent_state.getBlock()==ModContent.getBlock("factory_hopper")) {
|
||||
insertion_item = held.copy();
|
||||
Overlay.show(player, new TextComponent("Insertion item: " + (insertion_item.getItem()==Items.LEVER ? "random" : insertion_item.toString()) + "/s"), 1000);
|
||||
Overlay.show(player, Component.literal("Insertion item: " + (insertion_item.getItem()==Items.LEVER ? "random" : insertion_item.toString()) + "/s"), 1000);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -12,7 +12,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -64,10 +63,6 @@ public class EdTreeCutter
|
|||
public TreeCutterBlock(long config, BlockBehaviour.Properties builder, final AABB[] unrotatedAABB)
|
||||
{ super(config, builder, unrotatedAABB); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -151,7 +146,7 @@ public class EdTreeCutter
|
|||
}
|
||||
|
||||
public TreeCutterTileEntity(BlockPos pos, BlockState state)
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state); }
|
||||
|
||||
public void readnbt(CompoundTag nbt)
|
||||
{ energy_ = nbt.getInt("energy"); }
|
||||
|
|
|
@ -13,11 +13,10 @@ import net.minecraft.core.Direction;
|
|||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.*;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
@ -47,6 +46,7 @@ import wile.engineersdecor.ModContent;
|
|||
import wile.engineersdecor.blocks.EdFurnace.FurnaceBlock;
|
||||
import wile.engineersdecor.libmc.blocks.StandardBlocks;
|
||||
import wile.engineersdecor.libmc.blocks.StandardEntityBlocks;
|
||||
import wile.engineersdecor.libmc.detail.Auxiliaries;
|
||||
import wile.engineersdecor.libmc.detail.Inventories;
|
||||
import wile.engineersdecor.libmc.detail.RfEnergy;
|
||||
import wile.engineersdecor.libmc.detail.RsSignals;
|
||||
|
@ -55,7 +55,6 @@ import wile.engineersdecor.libmc.ui.Guis;
|
|||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class EdWasteIncinerator
|
||||
|
@ -82,10 +81,6 @@ public class EdWasteIncinerator
|
|||
public WasteIncineratorBlock(long config, BlockBehaviour.Properties builder, final AABB unrotatedAABB)
|
||||
{ super(config, builder, unrotatedAABB); }
|
||||
|
||||
@Override
|
||||
public ResourceLocation getBlockRegistryName()
|
||||
{ return getRegistryName(); }
|
||||
|
||||
@Override
|
||||
public boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return true; }
|
||||
|
@ -159,7 +154,7 @@ public class EdWasteIncinerator
|
|||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void animateTick(BlockState state, Level world, BlockPos pos, Random rnd)
|
||||
public void animateTick(BlockState state, Level world, BlockPos pos, RandomSource rnd)
|
||||
{
|
||||
if((state.getBlock()!=this) || (!state.getValue(LIT))) return;
|
||||
final double rv = rnd.nextDouble();
|
||||
|
@ -194,7 +189,7 @@ public class EdWasteIncinerator
|
|||
private final LazyOptional<IEnergyStorage> energy_handler_ = battery_.createEnergyHandler();
|
||||
|
||||
public WasteIncineratorTileEntity(BlockPos pos, BlockState state)
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); reset(); }
|
||||
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock()), pos, state); reset(); }
|
||||
|
||||
public CompoundTag getnbt()
|
||||
{ return writenbt(new CompoundTag()); }
|
||||
|
@ -241,7 +236,7 @@ public class EdWasteIncinerator
|
|||
|
||||
@Override
|
||||
public Component getName()
|
||||
{ final Block block=getBlockState().getBlock(); return new TextComponent((block!=null) ? block.getDescriptionId() : "Small Waste Incinerator"); }
|
||||
{ return Auxiliaries.localizable(getBlockState().getBlock().getDescriptionId()); }
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
|
|
|
@ -10,28 +10,17 @@
|
|||
package wile.engineersdecor.detail;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import wile.engineersdecor.blocks.EdCraftingTable;
|
||||
import wile.engineersdecor.blocks.EdCraftingTable.CraftingTableBlock;
|
||||
import wile.engineersdecor.blocks.EdLabeledCrate;
|
||||
import wile.engineersdecor.libmc.detail.Auxiliaries;
|
||||
|
||||
|
||||
public class ModRenderers
|
||||
|
@ -65,110 +54,4 @@ public class ModRenderers
|
|||
{}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
// Crafting table
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class CraftingTableTer implements BlockEntityRenderer<EdCraftingTable.CraftingTableTileEntity>
|
||||
{
|
||||
private static int tesr_error_counter = 16;
|
||||
private static final float scaler = 0.1f;
|
||||
private static final float gap = 0.19f;
|
||||
private static final float[] yrotations = {0, 90, 180, 270}; // [hdirection] S-W-N-E
|
||||
private static final float[][][] offsets = { // [hdirection][slotindex][xz]
|
||||
{ {-1,-1},{+0,-1},{+1,-1}, {-1,+0},{+0,+0},{+1,+0}, {-1,+1},{+0,+1},{+1,+1} }, // S
|
||||
{ {+1,-1},{+1,+0},{+1,+1}, {+0,-1},{+0,+0},{+0,+1}, {-1,-1},{-1,+0},{-1,+1} }, // W
|
||||
{ {+1,+1},{+0,+1},{-1,+1}, {+1,+0},{+0,+0},{-1,+0}, {+1,-1},{+0,-1},{-1,-1} }, // N
|
||||
{ {-1,+1},{-1,+0},{-1,-1}, {+0,+1},{+0,+0},{+0,-1}, {+1,+1},{+1,+0},{+1,-1} }, // E
|
||||
};
|
||||
private final BlockEntityRendererProvider.Context renderer_;
|
||||
|
||||
public CraftingTableTer(BlockEntityRendererProvider.Context renderer)
|
||||
{ this.renderer_ = renderer; }
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void render(final EdCraftingTable.CraftingTableTileEntity te, float unused1, PoseStack mxs, MultiBufferSource buf, int i5, int overlayTexture)
|
||||
{
|
||||
if(tesr_error_counter <= 0) return;
|
||||
try {
|
||||
final BlockState state = te.getLevel().getBlockState(te.getBlockPos());
|
||||
if(!(state.getBlock() instanceof EdCraftingTable.CraftingTableBlock)) return;
|
||||
final int di = Mth.clamp(state.getValue(CraftingTableBlock.HORIZONTAL_FACING).get2DDataValue(), 0, 3);
|
||||
long posrnd = te.getBlockPos().asLong();
|
||||
posrnd = (posrnd>>16)^(posrnd<<1);
|
||||
for(int i=0; i<9; ++i) {
|
||||
final ItemStack stack = te.mainInventory().getItem(i);
|
||||
if(stack.isEmpty()) continue;
|
||||
float prnd = ((float)(((Integer.rotateRight(stack.getItem().hashCode()^(int)posrnd,(stack.getCount()+i)&31)))&1023))/1024f;
|
||||
float rndo = gap * ((prnd*0.1f)-0.05f);
|
||||
float ox = gap * offsets[di][i][0], oz = gap * offsets[di][i][1];
|
||||
float oy = 0.5f;
|
||||
float ry = ((yrotations[di]+180) + ((prnd*60)-30)) % 360;
|
||||
if(stack.isEmpty()) return;
|
||||
mxs.pushPose();
|
||||
mxs.translate(0.5+ox, 0.5+oy, 0.5+oz);
|
||||
mxs.mulPose(Vector3f.XP.rotationDegrees(90.0f));
|
||||
mxs.mulPose(Vector3f.ZP.rotationDegrees(ry));
|
||||
mxs.translate(rndo, rndo, 0);
|
||||
mxs.scale(scaler, scaler, scaler);
|
||||
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.FIXED, i5, overlayTexture, mxs, buf, 0);
|
||||
mxs.popPose();
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
if(--tesr_error_counter<=0) {
|
||||
Auxiliaries.logger().error("TER was disabled because broken, exception was: " + e.getMessage());
|
||||
Auxiliaries.logger().error(e.getStackTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
// Labeled Crate
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class DecorLabeledCrateTer implements BlockEntityRenderer<EdLabeledCrate.LabeledCrateTileEntity>
|
||||
{
|
||||
private static int tesr_error_counter = 4;
|
||||
private static final float scaler = 0.35f;
|
||||
private static final double[][] tr = { // [hdirection=S-W-N-E][param]
|
||||
{ +8.0/32, -8.0/32, +15.5/32, 180.0 }, // N
|
||||
{ -15.5/32, -8.0/32, +8.0/32, 90.0 }, // E
|
||||
{ -8.0/32, -8.0/32, -15.5/32, 0.0 }, // S param=tx,ty,tz,ry
|
||||
{ +15.5/32, -8.0/32, -8.0/32, 270.0 }, // W
|
||||
};
|
||||
private final BlockEntityRendererProvider.Context renderer_;
|
||||
|
||||
public DecorLabeledCrateTer(BlockEntityRendererProvider.Context renderer)
|
||||
{ this.renderer_ = renderer; }
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void render(final EdLabeledCrate.LabeledCrateTileEntity te, float unused1, PoseStack mxs, MultiBufferSource buf, int i5, int overlayTexture)
|
||||
{
|
||||
if(tesr_error_counter<=0) return;
|
||||
try {
|
||||
final ItemStack stack = te.getItemFrameStack();
|
||||
if(stack.isEmpty()) return;
|
||||
final BlockState state = te.getLevel().getBlockState(te.getBlockPos());
|
||||
if(!(state.getBlock() instanceof EdLabeledCrate.LabeledCrateBlock)) return;
|
||||
final int di = Mth.clamp(state.getValue(EdLabeledCrate.LabeledCrateBlock.HORIZONTAL_FACING).get2DDataValue(), 0, 3);
|
||||
double ox = tr[di][0], oy = tr[di][1], oz = tr[di][2];
|
||||
float ry = (float)tr[di][3];
|
||||
mxs.pushPose();
|
||||
mxs.translate(0.5+ox, 0.5+oy, 0.5+oz);
|
||||
mxs.mulPose(Vector3f.YP.rotationDegrees(ry));
|
||||
mxs.scale(scaler, scaler, scaler);
|
||||
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.FIXED, i5, overlayTexture, mxs, buf, 0);
|
||||
mxs.popPose();
|
||||
} catch(Throwable e) {
|
||||
if(--tesr_error_counter<=0) {
|
||||
Auxiliaries.logger().error("TER was disabled (because broken), exception was: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
* JEI plugin (see https://github.com/mezz/JustEnoughItems/wiki/Creating-Plugins)
|
||||
*/
|
||||
package wile.engineersdecor.eapi.jei;
|
||||
/*
|
||||
|
||||
public class JEIPlugin {}
|
||||
*/
|
||||
/*
|
||||
|
||||
import mezz.jei.api.constants.RecipeTypes;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
|
@ -41,17 +42,6 @@ public class JEIPlugin implements mezz.jei.api.IModPlugin
|
|||
@Override
|
||||
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration)
|
||||
{
|
||||
if(!ModConfig.isOptedOut(ModContent.getBlock("metal_crafting_table"))) {
|
||||
try {
|
||||
registration.addRecipeTransferHandler(
|
||||
EdCraftingTable.CraftingTableUiContainer.class,
|
||||
RecipeTypes.CRAFTING,
|
||||
1, 9, 10, 36+CraftingTableTileEntity.NUM_OF_STORAGE_SLOTS
|
||||
);
|
||||
} catch(Throwable e) {
|
||||
Auxiliaries.logger().warn("Exception in JEI crafting table handler registration: '" + e.getMessage() + "'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,9 +71,6 @@ public class JEIPlugin implements mezz.jei.api.IModPlugin
|
|||
@Override
|
||||
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration)
|
||||
{
|
||||
if(!ModConfig.isOptedOut(ModContent.getBlock("metal_crafting_table"))) {
|
||||
registration.addRecipeCatalyst(new ItemStack(ModContent.getBlock("metal_crafting_table")), RecipeTypes.CRAFTING);
|
||||
}
|
||||
if(!ModConfig.isOptedOut(ModContent.getBlock("small_lab_furnace"))) {
|
||||
registration.addRecipeCatalyst(new ItemStack(ModContent.getBlock("small_lab_furnace")), RecipeTypes.SMELTING);
|
||||
}
|
||||
|
@ -92,3 +79,4 @@ public class JEIPlugin implements mezz.jei.api.IModPlugin
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -5,10 +5,6 @@
|
|||
* @license MIT (see https://opensource.org/licenses/MIT)
|
||||
*
|
||||
* Common functionality class for decor blocks.
|
||||
* Mainly needed for:
|
||||
* - MC block defaults.
|
||||
* - Tooltip functionality
|
||||
* - Model initialization
|
||||
*/
|
||||
package wile.engineersdecor.libmc.blocks;
|
||||
|
||||
|
@ -60,6 +56,7 @@ import java.util.*;
|
|||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class StandardBlocks
|
||||
{
|
||||
|
@ -102,12 +99,6 @@ public class StandardBlocks
|
|||
}
|
||||
}
|
||||
|
||||
public interface IBlockItemFactory
|
||||
{
|
||||
// BlockItem factory for item registry. Only invoked once.
|
||||
BlockItem getBlockItem(Block block, Item.Properties builder);
|
||||
}
|
||||
|
||||
public static class BaseBlock extends Block implements IStandardBlock, SimpleWaterloggedBlock
|
||||
{
|
||||
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
* Common functionality class for blocks with block entities.
|
||||
*/
|
||||
package wile.engineersdecor.libmc.blocks;
|
||||
import wile.engineersdecor.libmc.detail.Registries;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@ -21,7 +22,6 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.gameevent.GameEventListener;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import wile.engineersdecor.libmc.detail.Registries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -31,8 +31,6 @@ public class StandardEntityBlocks
|
|||
public interface IStandardEntityBlock<ET extends StandardBlockEntity> extends EntityBlock
|
||||
{
|
||||
|
||||
ResourceLocation getBlockRegistryName();
|
||||
|
||||
default boolean isBlockEntityTicking(Level world, BlockState state)
|
||||
{ return false; }
|
||||
|
||||
|
@ -49,7 +47,7 @@ public class StandardEntityBlocks
|
|||
@Nullable
|
||||
default BlockEntity newBlockEntity(BlockPos pos, BlockState state)
|
||||
{
|
||||
BlockEntityType<?> tet = Registries.getBlockEntityTypeOfBlock(getBlockRegistryName().getPath());
|
||||
BlockEntityType<?> tet = Registries.getBlockEntityTypeOfBlock(state.getBlock());
|
||||
return (tet==null) ? null : tet.create(pos, state);
|
||||
}
|
||||
|
||||
|
@ -60,7 +58,7 @@ public class StandardEntityBlocks
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
default <T extends BlockEntity> GameEventListener getListener(Level world, T te)
|
||||
default <T extends BlockEntity> GameEventListener getListener(ServerLevel world, T te)
|
||||
{ return null; }
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,11 @@ import net.minecraft.ChatFormatting;
|
|||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.ComponentUtils;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
@ -34,7 +35,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -42,10 +43,10 @@ import java.io.BufferedReader;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -124,27 +125,27 @@ public class Auxiliaries
|
|||
* Text localization wrapper, implicitly prepends `MODID` to the
|
||||
* translation keys. Forces formatting argument, nullable if no special formatting shall be applied..
|
||||
*/
|
||||
public static TranslatableComponent localizable(String modtrkey, Object... args)
|
||||
{ return new TranslatableComponent((modtrkey.startsWith("block.") || (modtrkey.startsWith("item."))) ? (modtrkey) : (modid+"."+modtrkey), args); }
|
||||
public static MutableComponent localizable(String modtrkey, Object... args)
|
||||
{ return Component.translatable((modtrkey.startsWith("block.") || (modtrkey.startsWith("item."))) ? (modtrkey) : (modid+"."+modtrkey), args); }
|
||||
|
||||
public static TranslatableComponent localizable(String modtrkey, @Nullable ChatFormatting color, Object... args)
|
||||
public static MutableComponent localizable(String modtrkey, @Nullable ChatFormatting color, Object... args)
|
||||
{
|
||||
TranslatableComponent tr = new TranslatableComponent(modid+"."+modtrkey, args);
|
||||
if(color!=null) tr.withStyle(color);
|
||||
final MutableComponent tr = Component.translatable(modid+"."+modtrkey, args);
|
||||
if(color!=null) tr.getStyle().applyFormat(color);
|
||||
return tr;
|
||||
}
|
||||
|
||||
public static TranslatableComponent localizable(String modtrkey)
|
||||
public static Component localizable(String modtrkey)
|
||||
{ return localizable(modtrkey, new Object[]{}); }
|
||||
|
||||
public static TranslatableComponent localizable_block_key(String blocksubkey)
|
||||
{ return new TranslatableComponent("block."+modid+"."+blocksubkey); }
|
||||
public static Component localizable_block_key(String blocksubkey)
|
||||
{ return Component.translatable("block."+modid+"."+blocksubkey); }
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static String localize(String translationKey, Object... args)
|
||||
{
|
||||
TranslatableComponent tr = new TranslatableComponent(translationKey, args);
|
||||
tr.withStyle(ChatFormatting.RESET);
|
||||
Component tr = Component.translatable(translationKey, args);
|
||||
tr.getStyle().applyFormat(ChatFormatting.RESET);
|
||||
final String ft = tr.getString();
|
||||
if(ft.contains("${")) {
|
||||
// Non-recursive, non-argument lang file entry cross referencing.
|
||||
|
@ -167,7 +168,7 @@ public class Auxiliaries
|
|||
if(!r) m = "";
|
||||
}
|
||||
}
|
||||
mt.appendReplacement(sb, Matcher.quoteReplacement((new TranslatableComponent(m)).getString().trim()));
|
||||
mt.appendReplacement(sb, Matcher.quoteReplacement((Component.translatable(m)).getString().trim()));
|
||||
}
|
||||
mt.appendTail(sb);
|
||||
return sb.toString();
|
||||
|
@ -183,6 +184,15 @@ public class Auxiliaries
|
|||
public static boolean hasTranslation(String key)
|
||||
{ return net.minecraft.client.resources.language.I18n.exists(key); }
|
||||
|
||||
public static MutableComponent join(Collection<? extends Component> components, String separator)
|
||||
{ return ComponentUtils.formatList(components, Component.literal(separator), Function.identity()); }
|
||||
|
||||
public static MutableComponent join(Component... components)
|
||||
{ final MutableComponent tc = Component.empty(); for(Component c:components) { tc.append(c); } return tc; }
|
||||
|
||||
public static boolean isEmpty(Component component)
|
||||
{ return component.getSiblings().isEmpty() && component.getString().isEmpty(); }
|
||||
|
||||
public static final class Tooltip
|
||||
{
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
@ -217,7 +227,7 @@ public class Auxiliaries
|
|||
if(tip_text.isEmpty()) return false;
|
||||
String[] tip_list = tip_text.split("\\r?\\n");
|
||||
for(String tip:tip_list) {
|
||||
tooltip.add(new TextComponent(tip.replaceAll("\\s+$","").replaceAll("^\\s+", "")).withStyle(ChatFormatting.GRAY));
|
||||
tooltip.add(Component.literal(tip.replaceAll("\\s+$","").replaceAll("^\\s+", "")).withStyle(ChatFormatting.GRAY));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -235,7 +245,7 @@ public class Auxiliaries
|
|||
public static boolean addInformation(String translation_key, List<Component> tooltip)
|
||||
{
|
||||
if(!Auxiliaries.hasTranslation(translation_key)) return false;
|
||||
tooltip.add(new TextComponent(localize(translation_key).replaceAll("\\s+$","").replaceAll("^\\s+", "")).withStyle(ChatFormatting.GRAY));
|
||||
tooltip.add(Component.literal(localize(translation_key).replaceAll("\\s+$","").replaceAll("^\\s+", "")).withStyle(ChatFormatting.GRAY));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -243,10 +253,7 @@ public class Auxiliaries
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
public static void playerChatMessage(final Player player, final String message)
|
||||
{
|
||||
String s = message.trim();
|
||||
if(!s.isEmpty()) player.sendMessage(new TranslatableComponent(s), new UUID(0,0));
|
||||
}
|
||||
{ player.displayClientMessage(Component.translatable(message.trim()), true); }
|
||||
|
||||
public static @Nullable Component unserializeTextComponent(String serialized)
|
||||
{ return Component.Serializer.fromJson(serialized); }
|
||||
|
@ -260,14 +267,28 @@ public class Auxiliaries
|
|||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean isInItemTag(Item item, ResourceLocation tag)
|
||||
{
|
||||
return ForgeRegistries.ITEMS.tags().stream().filter(tg->tg.getKey().location().equals(tag)).anyMatch(tk->tk.contains(item));
|
||||
}
|
||||
{ return ForgeRegistries.ITEMS.tags().stream().filter(tg->tg.getKey().location().equals(tag)).anyMatch(tk->tk.contains(item)); }
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean isInBlockTag(Block block, ResourceLocation tag)
|
||||
{ return ForgeRegistries.BLOCKS.tags().stream().filter(tg->tg.getKey().location().equals(tag)).anyMatch(tk->tk.contains(block)); }
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ResourceLocation getResourceLocation(Item item)
|
||||
{ return Registry.ITEM.getKey(item); }
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ResourceLocation getResourceLocation(Block block)
|
||||
{ return Registry.BLOCK.getKey(block); }
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ResourceLocation getResourceLocation(net.minecraft.world.inventory.MenuType<?> menu)
|
||||
{ return Registry.MENU.getKey(menu); }
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ResourceLocation getResourceLocation(net.minecraft.world.level.material.Fluid fluid)
|
||||
{ return Registry.FLUID.getKey(fluid); }
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------
|
||||
// Item NBT data
|
||||
// -------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -43,7 +43,14 @@ public class Crafting
|
|||
protected static final CraftingGrid instance3x3 = new CraftingGrid(3,3);
|
||||
|
||||
protected CraftingGrid(int width, int height)
|
||||
{ super(new AbstractContainerMenu(null,0) { public boolean stillValid(Player player) { return false; } }, width, height); }
|
||||
{ super(
|
||||
new AbstractContainerMenu(null,0) {
|
||||
public boolean stillValid(Player player) { return false; }
|
||||
public ItemStack quickMoveStack(Player player, int slot) {return ItemStack.EMPTY; }
|
||||
}
|
||||
, width, height
|
||||
);
|
||||
}
|
||||
|
||||
protected void fill(Container grid)
|
||||
{ for(int i=0; i<getContainerSize(); ++i) setItem(i, i>=grid.getContainerSize() ? ItemStack.EMPTY : grid.getItem(i)); }
|
||||
|
|
|
@ -12,7 +12,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.TagTypes;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.*;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
@ -827,7 +826,7 @@ public class Inventories
|
|||
public List<ItemStack> stacks()
|
||||
{ return stacks_; }
|
||||
|
||||
public BlockEntity getTileEntity()
|
||||
public BlockEntity getBlockEntity()
|
||||
{ return te_; }
|
||||
|
||||
public StorageInventory setOpenAction(Consumer<Player> fn)
|
||||
|
@ -922,7 +921,8 @@ public class Inventories
|
|||
public static void give(Player entity, ItemStack stack)
|
||||
{ ItemHandlerHelper.giveItemToPlayer(entity, stack); }
|
||||
|
||||
public static void setItemInPlayerHand(Player player, InteractionHand hand, ItemStack stack) {
|
||||
public static void setItemInPlayerHand(Player player, InteractionHand hand, ItemStack stack)
|
||||
{
|
||||
if(stack.isEmpty()) stack = ItemStack.EMPTY;
|
||||
if(hand == InteractionHand.MAIN_HAND) {
|
||||
player.getInventory().items.set(player.getInventory().selected, stack);
|
||||
|
@ -957,7 +957,6 @@ public class Inventories
|
|||
return stacks;
|
||||
}
|
||||
|
||||
|
||||
public static CompoundTag writeNbtStacks(CompoundTag nbt, String key, NonNullList<ItemStack> stacks, boolean omit_trailing_empty)
|
||||
{
|
||||
CompoundTag stacknbt = new CompoundTag();
|
||||
|
|
|
@ -12,7 +12,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@ -20,12 +19,15 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkDirection;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.simple.SimpleChannel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
|
@ -45,6 +47,8 @@ public class Networking
|
|||
DEFAULT_CHANNEL.registerMessage(++discr, PacketTileNotifyServerToClient.class, PacketTileNotifyServerToClient::compose, PacketTileNotifyServerToClient::parse, PacketTileNotifyServerToClient.Handler::handle);
|
||||
DEFAULT_CHANNEL.registerMessage(++discr, PacketContainerSyncClientToServer.class, PacketContainerSyncClientToServer::compose, PacketContainerSyncClientToServer::parse, PacketContainerSyncClientToServer.Handler::handle);
|
||||
DEFAULT_CHANNEL.registerMessage(++discr, PacketContainerSyncServerToClient.class, PacketContainerSyncServerToClient::compose, PacketContainerSyncServerToClient::parse, PacketContainerSyncServerToClient.Handler::handle);
|
||||
DEFAULT_CHANNEL.registerMessage(++discr, PacketNbtNotifyClientToServer.class, PacketNbtNotifyClientToServer::compose, PacketNbtNotifyClientToServer::parse, PacketNbtNotifyClientToServer.Handler::handle);
|
||||
DEFAULT_CHANNEL.registerMessage(++discr, PacketNbtNotifyServerToClient.class, PacketNbtNotifyServerToClient::compose, PacketNbtNotifyServerToClient::parse, PacketNbtNotifyServerToClient.Handler::handle);
|
||||
DEFAULT_CHANNEL.registerMessage(++discr, OverlayTextMessage.class, OverlayTextMessage::compose, OverlayTextMessage::parse, OverlayTextMessage.Handler::handle);
|
||||
}
|
||||
|
||||
|
@ -138,7 +142,6 @@ public class Networking
|
|||
public static void handle(final PacketTileNotifyServerToClient pkt, final Supplier<NetworkEvent.Context> ctx)
|
||||
{
|
||||
ctx.get().enqueueWork(() -> {
|
||||
if((pkt.nbt==null) || (pkt.pos==null)) return;
|
||||
Level world = SidedProxy.getWorldClientSide();
|
||||
if(world == null) return;
|
||||
final BlockEntity te = world.getBlockEntity(pkt.pos);
|
||||
|
@ -251,6 +254,80 @@ public class Networking
|
|||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
// World notifications
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static class PacketNbtNotifyClientToServer
|
||||
{
|
||||
public static final Map<String, BiConsumer<Player, CompoundTag>> handlers = new HashMap<>();
|
||||
final CompoundTag nbt;
|
||||
|
||||
public static void sendToServer(CompoundTag nbt)
|
||||
{ if(nbt!=null) DEFAULT_CHANNEL.sendToServer(new PacketNbtNotifyClientToServer(nbt)); }
|
||||
|
||||
public PacketNbtNotifyClientToServer(CompoundTag nbt)
|
||||
{ this.nbt = nbt; }
|
||||
|
||||
public static PacketNbtNotifyClientToServer parse(final FriendlyByteBuf buf)
|
||||
{ return new PacketNbtNotifyClientToServer(buf.readNbt()); }
|
||||
|
||||
public static void compose(final PacketNbtNotifyClientToServer pkt, final FriendlyByteBuf buf)
|
||||
{ buf.writeNbt(pkt.nbt); }
|
||||
|
||||
public static class Handler
|
||||
{
|
||||
public static void handle(final PacketNbtNotifyClientToServer pkt, final Supplier<NetworkEvent.Context> ctx)
|
||||
{
|
||||
ctx.get().enqueueWork(() -> {
|
||||
final ServerPlayer player = ctx.get().getSender();
|
||||
if(player==null) return;
|
||||
final String hnd = pkt.nbt.getString("hnd");
|
||||
if(hnd.isEmpty()) return;
|
||||
if(handlers.containsKey(hnd)) handlers.get(hnd).accept(player, pkt.nbt);
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PacketNbtNotifyServerToClient
|
||||
{
|
||||
public static final Map<String, Consumer<CompoundTag>> handlers = new HashMap<>();
|
||||
final CompoundTag nbt;
|
||||
|
||||
public static void sendToPlayer(Player player, CompoundTag nbt)
|
||||
{
|
||||
if((!(player instanceof ServerPlayer)) || (player instanceof FakePlayer) || (nbt==null)) return;
|
||||
DEFAULT_CHANNEL.sendTo(new PacketNbtNotifyServerToClient(nbt), ((ServerPlayer)player).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
|
||||
}
|
||||
|
||||
public static void sendToPlayers(Level world, CompoundTag nbt)
|
||||
{ for(Player player: world.players()) sendToPlayer(player, nbt); }
|
||||
|
||||
public PacketNbtNotifyServerToClient(CompoundTag nbt)
|
||||
{ this.nbt = nbt; }
|
||||
|
||||
public static PacketNbtNotifyServerToClient parse(final FriendlyByteBuf buf)
|
||||
{ return new PacketNbtNotifyServerToClient(buf.readNbt()); }
|
||||
|
||||
public static void compose(final PacketNbtNotifyServerToClient pkt, final FriendlyByteBuf buf)
|
||||
{ buf.writeNbt(pkt.nbt); }
|
||||
|
||||
public static class Handler
|
||||
{
|
||||
public static void handle(final PacketNbtNotifyServerToClient pkt, final Supplier<NetworkEvent.Context> ctx)
|
||||
{
|
||||
ctx.get().enqueueWork(() -> {
|
||||
final String hnd = pkt.nbt.getString("hnd");
|
||||
if(hnd.isEmpty()) return;
|
||||
if(handlers.containsKey(hnd)) handlers.get(hnd).accept(pkt.nbt);
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
// Main window GUI text message
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -269,12 +346,12 @@ public class Networking
|
|||
|
||||
public static void sendToPlayer(Player player, Component message, int delay)
|
||||
{
|
||||
if((!(player instanceof ServerPlayer)) || (player instanceof FakePlayer)) return;
|
||||
if((!(player instanceof ServerPlayer)) || (player instanceof FakePlayer) || Auxiliaries.isEmpty(message)) return;
|
||||
DEFAULT_CHANNEL.sendTo(new OverlayTextMessage(message, delay), ((ServerPlayer)player).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
|
||||
}
|
||||
|
||||
public OverlayTextMessage()
|
||||
{ data_ = new TranslatableComponent("[unset]"); }
|
||||
{ data_ = Component.translatable("[unset]"); }
|
||||
|
||||
public OverlayTextMessage(final Component tct, int delay)
|
||||
{ data_ = tct.copy(); delay_ = delay; }
|
||||
|
@ -284,7 +361,7 @@ public class Networking
|
|||
try {
|
||||
return new OverlayTextMessage(buf.readComponent(), DISPLAY_TIME_MS);
|
||||
} catch(Throwable e) {
|
||||
return new OverlayTextMessage(new TranslatableComponent("[incorrect translation]"), DISPLAY_TIME_MS);
|
||||
return new OverlayTextMessage(Component.translatable("[incorrect translation]"), DISPLAY_TIME_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import net.minecraftforge.common.crafting.conditions.ICondition;
|
|||
import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -90,7 +90,7 @@ public class OptionalRecipeCondition implements ICondition
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean test()
|
||||
public boolean test(IContext context)
|
||||
{
|
||||
if(without_recipes) return false;
|
||||
if((experimental) && (!with_experimental)) return false;
|
||||
|
|
|
@ -10,19 +10,34 @@ package wile.engineersdecor.libmc.detail;
|
|||
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderLevelLastEvent;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class Overlay
|
||||
{
|
||||
|
@ -40,6 +55,12 @@ public class Overlay
|
|||
public static void show(Player player, final Component message, int delay)
|
||||
{ Networking.OverlayTextMessage.sendToPlayer(player, message, delay); }
|
||||
|
||||
public static void show(BlockState state, BlockPos pos)
|
||||
{ show(state, pos, 100); }
|
||||
|
||||
public static void show(BlockState state, BlockPos pos, int displayTimeoutMs)
|
||||
{ DistExecutor.unsafeRunWhenOn(Dist.CLIENT, ()->(()->TextOverlayGui.show(state, pos, displayTimeoutMs))); } // Only called when client side
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Client side handler
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -48,15 +69,19 @@ public class Overlay
|
|||
@OnlyIn(Dist.CLIENT)
|
||||
public static class TextOverlayGui extends Screen
|
||||
{
|
||||
private static final Component EMPTY_TEXT = new TextComponent("");
|
||||
private static final Component EMPTY_TEXT = Component.literal("");
|
||||
private static final BlockState EMPTY_STATE = null;
|
||||
private static double overlay_y_ = 0.75;
|
||||
private static int text_color_ = 0x00ffaa00;
|
||||
private static int border_color_ = 0xaa333333;
|
||||
private static int background_color1_ = 0xaa333333;
|
||||
private static int background_color2_ = 0xaa444444;
|
||||
private final Minecraft mc;
|
||||
private static long deadline_;
|
||||
private static Component text_;
|
||||
private static long text_deadline_ = 0;
|
||||
private static Component text_ = EMPTY_TEXT;
|
||||
private static long state_deadline_ = 0;
|
||||
private static @Nullable BlockState state_ = EMPTY_STATE;
|
||||
private static BlockPos pos_ = BlockPos.ZERO;
|
||||
|
||||
public static void on_config(double overlay_y)
|
||||
{ on_config(overlay_y, 0x00ffaa00, 0xaa333333, 0xaa333333, 0xaa444444); }
|
||||
|
@ -74,19 +99,25 @@ public class Overlay
|
|||
{ return text_; }
|
||||
|
||||
public static synchronized long deadline()
|
||||
{ return deadline_; }
|
||||
{ return text_deadline_; }
|
||||
|
||||
public static synchronized void hide()
|
||||
{ deadline_ = 0; text_ = EMPTY_TEXT; }
|
||||
{ text_deadline_ = 0; text_ = EMPTY_TEXT; }
|
||||
|
||||
public static synchronized void show(Component s, int displayTimeoutMs)
|
||||
{ text_ = (s==null)?(EMPTY_TEXT):(s.copy()); deadline_ = System.currentTimeMillis() + displayTimeoutMs; }
|
||||
{ text_ = (s==null)?(EMPTY_TEXT):(s.copy()); text_deadline_ = System.currentTimeMillis() + displayTimeoutMs; }
|
||||
|
||||
public static synchronized void show(String s, int displayTimeoutMs)
|
||||
{ text_ = ((s==null)||(s.isEmpty()))?(EMPTY_TEXT):(new TextComponent(s)); deadline_ = System.currentTimeMillis() + displayTimeoutMs; }
|
||||
{ text_ = ((s==null)||(s.isEmpty()))?(EMPTY_TEXT):(Component.literal(s)); text_deadline_ = System.currentTimeMillis() + displayTimeoutMs; }
|
||||
|
||||
public static synchronized void show(BlockState state, BlockPos pos, int displayTimeoutMs)
|
||||
{ pos_ = new BlockPos(pos); state_ = state; state_deadline_ = System.currentTimeMillis() + displayTimeoutMs; }
|
||||
|
||||
private static synchronized Optional<Tuple<BlockState,BlockPos>> state_pos()
|
||||
{ return ((state_deadline_ < System.currentTimeMillis()) || (state_==EMPTY_STATE)) ? Optional.empty() : Optional.of(new Tuple<>(state_, pos_)); }
|
||||
|
||||
TextOverlayGui()
|
||||
{ super(new TextComponent("")); mc = SidedProxy.mc(); }
|
||||
{ super(Component.literal("")); mc = SidedProxy.mc(); }
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderGui(RenderGameOverlayEvent.Post event)
|
||||
|
@ -96,7 +127,7 @@ public class Overlay
|
|||
if(text()==EMPTY_TEXT) return;
|
||||
String txt = text().getString();
|
||||
if(txt.isEmpty()) return;
|
||||
PoseStack mxs = event.getMatrixStack();
|
||||
PoseStack mxs = event.getPoseStack();
|
||||
final Window win = mc.getWindow();
|
||||
final Font fr = mc.font;
|
||||
final boolean was_unicode = fr.isBidirectional();
|
||||
|
@ -111,6 +142,30 @@ public class Overlay
|
|||
vLine(mxs, cx+(w/2)+2, cy-2, cy+h+2, 0xaa333333);
|
||||
drawCenteredString(mxs, fr, text(), cx , cy+1, 0x00ffaa00);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderWorldOverlay(RenderLevelLastEvent event)
|
||||
{
|
||||
final Optional<Tuple<BlockState,BlockPos>> sp = state_pos();
|
||||
if(sp.isEmpty()) return;
|
||||
final ClientLevel world = Minecraft.getInstance().level;
|
||||
final LocalPlayer player = Minecraft.getInstance().player;
|
||||
if((player==null) || (world==null)) return;
|
||||
final BlockState state = sp.get().getA();
|
||||
final BlockPos pos = sp.get().getB();
|
||||
@SuppressWarnings("deprecation")
|
||||
final int light = (world.hasChunkAt(pos)) ? LightTexture.pack(world.getBrightness(LightLayer.BLOCK, pos), world.getBrightness(LightLayer.SKY, pos)) : LightTexture.pack(15, 15);
|
||||
final MultiBufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||
final PoseStack mxs = event.getPoseStack();
|
||||
final double px = Mth.lerp(event.getPartialTick(), player.xo, player.getX());
|
||||
final double py = Mth.lerp(event.getPartialTick(), player.yo, player.getY());
|
||||
final double pz = Mth.lerp(event.getPartialTick(), player.zo, player.getZ());
|
||||
mxs.pushPose();
|
||||
mxs.translate((pos.getX()-px), (pos.getY()-py-player.getEyeHeight()), (pos.getZ()-pz));
|
||||
Minecraft.getInstance().getBlockRenderer().renderSingleBlock(state, mxs, buffer, light, OverlayTexture.NO_OVERLAY, EmptyModelData.INSTANCE);
|
||||
mxs.popPose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,25 +7,27 @@
|
|||
* Common game registry handling.
|
||||
*/
|
||||
package wile.engineersdecor.libmc.detail;
|
||||
import wile.engineersdecor.libmc.blocks.StandardBlocks;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -34,30 +36,43 @@ public class Registries
|
|||
private static String modid = null;
|
||||
private static String creative_tab_icon = "";
|
||||
private static CreativeModeTab creative_tab = null;
|
||||
|
||||
private static final List<Tuple<String, Supplier<? extends Block>>> block_suppliers = new ArrayList<>();
|
||||
private static final List<Tuple<String, Supplier<? extends Item>>> item_suppliers = new ArrayList<>();
|
||||
private static final List<Tuple<String, Supplier<? extends BlockEntityType<?>>>> block_entity_type_suppliers = new ArrayList<>();
|
||||
private static final List<Tuple<String, Supplier<? extends EntityType<?>>>> entity_type_suppliers = new ArrayList<>();
|
||||
private static final List<Tuple<String, Supplier<? extends MenuType<?>>>> menu_type_suppliers = new ArrayList<>();
|
||||
private static final List<String> block_item_order = new ArrayList<>();
|
||||
|
||||
private static final Map<String, Block> registered_blocks = new HashMap<>();
|
||||
private static final Map<String, Item> registered_items = new HashMap<>();
|
||||
private static final Map<String, BlockEntityType<?>> registered_block_entity_types = new HashMap<>();
|
||||
private static final Map<String, EntityType<?>> registered_entity_types = new HashMap<>();
|
||||
private static final Map<String, MenuType<?>> registered_menu_types = new HashMap<>();
|
||||
private static final Map<String, TagKey<Block>> registered_block_tag_keys = new HashMap<>();
|
||||
private static final Map<String, TagKey<Item>> registered_item_tag_keys = new HashMap<>();
|
||||
|
||||
public static void init(String mod_id, String creative_tab_icon_item_name)
|
||||
{ modid = mod_id; creative_tab_icon=creative_tab_icon_item_name; }
|
||||
private static final Map<String, RegistryObject<Block>> registered_blocks = new HashMap<>();
|
||||
private static final Map<String, RegistryObject<Item>> registered_items = new HashMap<>();
|
||||
private static final Map<String, RegistryObject<BlockEntityType<?>>> registered_block_entity_types = new HashMap<>();
|
||||
private static final Map<String, RegistryObject<EntityType<?>>> registered_entity_types = new HashMap<>();
|
||||
private static final Map<String, RegistryObject<MenuType<?>>> registered_menu_types = new HashMap<>();
|
||||
private static final Map<String, RegistryObject<RecipeSerializer<?>>> recipe_serializers = new HashMap<>();
|
||||
|
||||
private static DeferredRegister<Block> BLOCKS;
|
||||
private static DeferredRegister<Item> ITEMS;
|
||||
private static DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES;
|
||||
private static DeferredRegister<MenuType<?>> MENUS;
|
||||
private static DeferredRegister<EntityType<?>> ENTITIES;
|
||||
private static DeferredRegister<RecipeSerializer<?>> RECIPE_SERIALIZERS;
|
||||
private static List<DeferredRegister<?>> MOD_REGISTRIES;
|
||||
|
||||
public static void init(String mod_id, String creative_tab_icon_item_name, Consumer<DeferredRegister<?>> registrar)
|
||||
{
|
||||
modid = mod_id;
|
||||
creative_tab_icon = creative_tab_icon_item_name;
|
||||
BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, modid);
|
||||
ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, modid);
|
||||
BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, modid);
|
||||
MENUS = DeferredRegister.create(ForgeRegistries.CONTAINERS, modid);
|
||||
ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, modid);
|
||||
RECIPE_SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, modid);
|
||||
List.of(BLOCKS, ITEMS, BLOCK_ENTITIES, MENUS, ENTITIES, RECIPE_SERIALIZERS).forEach(registrar);
|
||||
}
|
||||
|
||||
|
||||
public static CreativeModeTab getCreativeModeTab()
|
||||
{
|
||||
if(creative_tab==null) {
|
||||
creative_tab = (new CreativeModeTab("tab" + modid) {
|
||||
public ItemStack makeIcon() { return new ItemStack(registered_items.get(creative_tab_icon)); }
|
||||
public ItemStack makeIcon() { return new ItemStack(getItem(creative_tab_icon)); }
|
||||
});
|
||||
}
|
||||
return creative_tab;
|
||||
|
@ -66,26 +81,35 @@ public class Registries
|
|||
// -------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static Block getBlock(String block_name)
|
||||
{ return registered_blocks.get(block_name); }
|
||||
{ return registered_blocks.get(block_name).get(); }
|
||||
|
||||
public static Item getItem(String name)
|
||||
{ return registered_items.get(name); }
|
||||
{ return registered_items.get(name).get(); }
|
||||
|
||||
public static EntityType<?> getEntityType(String name)
|
||||
{ return registered_entity_types.get(name); }
|
||||
{ return registered_entity_types.get(name).get(); }
|
||||
|
||||
public static BlockEntityType<?> getBlockEntityType(String block_name)
|
||||
{ return registered_block_entity_types.get(block_name); }
|
||||
{ return registered_block_entity_types.get(block_name).get(); }
|
||||
|
||||
public static MenuType<?> getMenuType(String name)
|
||||
{ return registered_menu_types.get(name); }
|
||||
{ return registered_menu_types.get(name).get(); }
|
||||
|
||||
public static RecipeSerializer<?> getRecipeSerializer(String name)
|
||||
{ return recipe_serializers.get(name).get(); }
|
||||
|
||||
public static BlockEntityType<?> getBlockEntityTypeOfBlock(String block_name)
|
||||
{ return getBlockEntityType("tet_"+block_name); }
|
||||
|
||||
public static BlockEntityType<?> getBlockEntityTypeOfBlock(Block block)
|
||||
{ return getBlockEntityTypeOfBlock(ForgeRegistries.BLOCKS.getKey(block).getPath()); }
|
||||
|
||||
public static MenuType<?> getMenuTypeOfBlock(String name)
|
||||
{ return getMenuType("ct_"+name); }
|
||||
|
||||
public static MenuType<?> getMenuTypeOfBlock(Block block)
|
||||
{ return getMenuTypeOfBlock(ForgeRegistries.BLOCKS.getKey(block).getPath()); }
|
||||
|
||||
public static TagKey<Block> getBlockTagKey(String name)
|
||||
{ return registered_block_tag_keys.get(name); }
|
||||
|
||||
|
@ -96,96 +120,57 @@ public class Registries
|
|||
|
||||
@Nonnull
|
||||
public static List<Block> getRegisteredBlocks()
|
||||
{ return Collections.unmodifiableList(registered_blocks.values().stream().toList()); }
|
||||
{ return Collections.unmodifiableList(registered_blocks.values().stream().map(RegistryObject::get).toList()); }
|
||||
|
||||
@Nonnull
|
||||
public static List<Item> getRegisteredItems()
|
||||
{ return Collections.unmodifiableList(registered_items.values().stream().toList()); }
|
||||
{ return Collections.unmodifiableList(registered_items.values().stream().map(RegistryObject::get).toList()); }
|
||||
|
||||
@Nonnull
|
||||
public static List<BlockEntityType<?>> getRegisteredBlockEntityTypes()
|
||||
{ return Collections.unmodifiableList(registered_block_entity_types.values().stream().toList()); }
|
||||
{ return Collections.unmodifiableList(registered_block_entity_types.values().stream().map(RegistryObject::get).toList()); }
|
||||
|
||||
@Nonnull
|
||||
public static List<EntityType<?>> getRegisteredEntityTypes()
|
||||
{ return Collections.unmodifiableList(registered_entity_types.values().stream().toList()); }
|
||||
{ return Collections.unmodifiableList(registered_entity_types.values().stream().map(RegistryObject::get).toList()); }
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Item> void addItem(String registry_name, Supplier<T> supplier)
|
||||
{
|
||||
item_suppliers.add(new Tuple<>(registry_name, ()->{
|
||||
final T instance = supplier.get();
|
||||
instance.setRegistryName(new ResourceLocation(modid, registry_name));
|
||||
return instance;
|
||||
}));
|
||||
}
|
||||
{ registered_items.put(registry_name, ITEMS.register(registry_name, supplier)); }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Block> void addBlock(String registry_name, Supplier<T> block_supplier)
|
||||
{
|
||||
block_suppliers.add(new Tuple<>(registry_name, ()->{
|
||||
final T instance = block_supplier.get();
|
||||
instance.setRegistryName(new ResourceLocation(modid, registry_name));
|
||||
return instance;
|
||||
}));
|
||||
registered_blocks.put(registry_name, BLOCKS.register(registry_name, block_supplier));
|
||||
registered_items.put(registry_name, ITEMS.register(registry_name, ()->new BlockItem(registered_blocks.get(registry_name).get(), (new Item.Properties()).tab(getCreativeModeTab()))));
|
||||
}
|
||||
|
||||
public static <TB extends Block, TI extends Item> void addBlock(String registry_name, Supplier<TB> block_supplier, Supplier<TI> item_supplier)
|
||||
{
|
||||
registered_blocks.put(registry_name, BLOCKS.register(registry_name, block_supplier));
|
||||
registered_items.put(registry_name, ITEMS.register(registry_name, item_supplier));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends BlockEntity> void addBlockEntityType(String registry_name, BlockEntityType.BlockEntitySupplier<T> ctor, String... block_names)
|
||||
{
|
||||
block_entity_type_suppliers.add(new Tuple<>(registry_name, ()->{
|
||||
registered_block_entity_types.put(registry_name, BLOCK_ENTITIES.register(registry_name, ()->{
|
||||
final Block[] blocks = Arrays.stream(block_names).map(s->{
|
||||
Block b = registered_blocks.get(s);
|
||||
Block b = BLOCKS.getEntries().stream().filter((ro)->ro.getId().getPath().equals(s)).findFirst().map(RegistryObject::get).orElse(null);
|
||||
if(b==null) Auxiliaries.logError("registered_blocks does not encompass '" + s + "'");
|
||||
return b;
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList()).toArray(new Block[]{});
|
||||
final BlockEntityType<T> instance = BlockEntityType.Builder.of(ctor, blocks).build(null);
|
||||
instance.setRegistryName(modid, registry_name);
|
||||
return instance;
|
||||
return BlockEntityType.Builder.of(ctor, blocks).build(null);
|
||||
}));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends BlockEntity> void addBlockEntityType(String registry_name, BlockEntityType.BlockEntitySupplier<T> ctor, Class<? extends Block> block_clazz)
|
||||
{
|
||||
block_entity_type_suppliers.add(new Tuple<>(registry_name, ()->{
|
||||
final Block[] blocks = registered_blocks.values().stream().filter(block_clazz::isInstance).collect(Collectors.toList()).toArray(new Block[]{});
|
||||
final BlockEntityType<T> instance = BlockEntityType.Builder.of(ctor, blocks).build(null);
|
||||
instance.setRegistryName(modid, registry_name);
|
||||
return instance;
|
||||
}));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends EntityType<?>> void addEntityType(String registry_name, Supplier<EntityType<?>> supplier)
|
||||
{ entity_type_suppliers.add(new Tuple<>(registry_name, supplier)); }
|
||||
{ registered_entity_types.put(registry_name, ENTITIES.register(registry_name, supplier)); }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends MenuType<?>> void addMenuType(String registry_name, MenuType.MenuSupplier<?> supplier)
|
||||
{
|
||||
menu_type_suppliers.add(new Tuple<>(registry_name, ()->{
|
||||
final MenuType<?> instance = new MenuType<>(supplier);
|
||||
instance.setRegistryName(modid, registry_name);
|
||||
return instance;
|
||||
}));
|
||||
}
|
||||
{ registered_menu_types.put(registry_name, MENUS.register(registry_name, ()->new MenuType<>(supplier))); }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void addBlock(String registry_name, Supplier<? extends Block> block_supplier, BlockEntityType.BlockEntitySupplier<?> block_entity_ctor)
|
||||
{
|
||||
addBlock(registry_name, block_supplier);
|
||||
addBlockEntityType("tet_"+registry_name, block_entity_ctor, registry_name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void addBlock(String registry_name, Supplier<? extends Block> block_supplier, BlockEntityType.BlockEntitySupplier<?> block_entity_ctor, MenuType.MenuSupplier<?> menu_type_supplier)
|
||||
{
|
||||
addBlock(registry_name, block_supplier);
|
||||
addBlockEntityType("tet_"+registry_name, block_entity_ctor, registry_name);
|
||||
addMenuType("ct_"+registry_name, menu_type_supplier);
|
||||
}
|
||||
public static void addRecipeSerializer(String registry_name, Supplier<? extends RecipeSerializer<?>> serializer_supplier)
|
||||
{ recipe_serializers.put(registry_name, RECIPE_SERIALIZERS.register(registry_name, serializer_supplier)); }
|
||||
|
||||
public static void addOptionalBlockTag(String tag_name, ResourceLocation... default_blocks)
|
||||
{
|
||||
|
@ -195,10 +180,7 @@ public class Registries
|
|||
registered_block_tag_keys.put(tag_name, key);
|
||||
}
|
||||
|
||||
public static void addOptionalBlockTag(String tag_name, String... default_blocks)
|
||||
{ addOptionalBlockTag(tag_name, Arrays.stream(default_blocks).map(ResourceLocation::new).collect(Collectors.toList()).toArray(new ResourceLocation[]{})); }
|
||||
|
||||
public static void addOptionalItemTag(String tag_name, ResourceLocation... default_items)
|
||||
public static void addOptionaItemTag(String tag_name, ResourceLocation... default_items)
|
||||
{
|
||||
final Set<Supplier<Item>> default_suppliers = new HashSet<>();
|
||||
for(ResourceLocation rl: default_items) default_suppliers.add(()->ForgeRegistries.ITEMS.getValue(rl));
|
||||
|
@ -206,77 +188,36 @@ public class Registries
|
|||
registered_item_tag_keys.put(tag_name, key);
|
||||
}
|
||||
|
||||
public static void addOptionalItemTag(String tag_name, String... default_items)
|
||||
{ addOptionalBlockTag(tag_name, Arrays.stream(default_items).map(ResourceLocation::new).collect(Collectors.toList()).toArray(new ResourceLocation[]{})); }
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static void onBlockRegistry(BiConsumer<ResourceLocation, Block> registration)
|
||||
public static <TB extends Block, TI extends Item> void addBlock(String registry_name, Supplier<TB> block_supplier, BiFunction<Block, Item.Properties, Item> item_builder)
|
||||
{
|
||||
block_suppliers.forEach(e->{
|
||||
final Block block = e.getB().get();
|
||||
final ResourceLocation rl = new ResourceLocation(modid, e.getA());
|
||||
registration.accept(rl, block);
|
||||
registered_blocks.put(e.getA(), block);
|
||||
block_item_order.add(e.getA());
|
||||
});
|
||||
block_suppliers.clear();
|
||||
addBlock(registry_name, block_supplier, ()->item_builder.apply(registered_blocks.get(registry_name).get(), (new Item.Properties()).tab(getCreativeModeTab())));
|
||||
}
|
||||
|
||||
public static void onItemRegistry(BiConsumer<ResourceLocation, Item> registration)
|
||||
public static void addBlock(String registry_name, Supplier<? extends Block> block_supplier, BlockEntityType.BlockEntitySupplier<?> block_entity_ctor)
|
||||
{
|
||||
block_item_order.forEach(regname->{
|
||||
Block block = registered_blocks.get(regname);
|
||||
final ResourceLocation rl = block.getRegistryName();
|
||||
Item item;
|
||||
if(block instanceof StandardBlocks.IBlockItemFactory) {
|
||||
item = ((StandardBlocks.IBlockItemFactory)block).getBlockItem(block, (new Item.Properties().tab(getCreativeModeTab())));
|
||||
} else {
|
||||
item = new BlockItem(block, (new Item.Properties().tab(getCreativeModeTab())));
|
||||
}
|
||||
item.setRegistryName(rl);
|
||||
registration.accept(rl, item);
|
||||
registered_items.put(rl.getPath(), item);
|
||||
});
|
||||
item_suppliers.forEach(e->{
|
||||
final Item item = e.getB().get();
|
||||
registration.accept(new ResourceLocation(modid, e.getA()), item);
|
||||
registered_items.put(e.getA(), item);
|
||||
});
|
||||
item_suppliers.clear();
|
||||
block_item_order.clear();
|
||||
addBlock(registry_name, block_supplier);
|
||||
addBlockEntityType("tet_"+registry_name, block_entity_ctor, registry_name);
|
||||
}
|
||||
|
||||
public static void onBlockEntityRegistry(BiConsumer<ResourceLocation, BlockEntityType<?>> registration)
|
||||
public static void addBlock(String registry_name, Supplier<? extends Block> block_supplier, BiFunction<Block, Item.Properties, Item> item_builder, BlockEntityType.BlockEntitySupplier<?> block_entity_ctor)
|
||||
{
|
||||
block_entity_type_suppliers.forEach(e->{
|
||||
final BlockEntityType<?> tet = e.getB().get();
|
||||
registration.accept(new ResourceLocation(modid, e.getA()), tet);
|
||||
registered_block_entity_types.put(e.getA(), tet);
|
||||
});
|
||||
block_entity_type_suppliers.clear();
|
||||
addBlock(registry_name, block_supplier, item_builder);
|
||||
addBlockEntityType("tet_"+registry_name, block_entity_ctor, registry_name);
|
||||
}
|
||||
|
||||
public static void onMenuTypeRegistry(BiConsumer<ResourceLocation, MenuType<?>> registration)
|
||||
public static void addBlock(String registry_name, Supplier<? extends Block> block_supplier, BiFunction<Block, Item.Properties, Item> item_builder, BlockEntityType.BlockEntitySupplier<?> block_entity_ctor, MenuType.MenuSupplier<?> menu_type_supplier)
|
||||
{
|
||||
menu_type_suppliers.forEach(e->{
|
||||
final MenuType<?> ct = e.getB().get();
|
||||
registration.accept(new ResourceLocation(modid, e.getA()), ct);
|
||||
registered_menu_types.put(e.getA(), ct);
|
||||
});
|
||||
menu_type_suppliers.clear();
|
||||
addBlock(registry_name, block_supplier, item_builder);
|
||||
addBlockEntityType("tet_"+registry_name, block_entity_ctor, registry_name);
|
||||
addMenuType("ct_"+registry_name, menu_type_supplier);
|
||||
}
|
||||
|
||||
public static void onEntityRegistry(BiConsumer<ResourceLocation, EntityType<?>> registration)
|
||||
public static void addBlock(String registry_name, Supplier<? extends Block> block_supplier, BlockEntityType.BlockEntitySupplier<?> block_entity_ctor, MenuType.MenuSupplier<?> menu_type_supplier)
|
||||
{
|
||||
entity_type_suppliers.forEach(e->{
|
||||
final ResourceLocation rl = new ResourceLocation(modid, e.getA());
|
||||
final EntityType<?> et = e.getB().get();
|
||||
et.setRegistryName(rl);
|
||||
registration.accept(rl, et);
|
||||
registered_entity_types.put(e.getA(), et);
|
||||
});
|
||||
entity_type_suppliers.clear();
|
||||
addBlock(registry_name, block_supplier, block_entity_ctor);
|
||||
addMenuType("ct_"+registry_name, menu_type_supplier);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,14 +29,18 @@ public class SidedProxy
|
|||
public static Minecraft mc()
|
||||
{ return proxy.mc(); }
|
||||
|
||||
@Nullable
|
||||
public static Optional<Boolean> isCtrlDown()
|
||||
{ return proxy.isCtrlDown(); }
|
||||
|
||||
@Nullable
|
||||
public static Optional<Boolean> isShiftDown()
|
||||
{ return proxy.isShiftDown(); }
|
||||
|
||||
public static Optional<String> getClipboard()
|
||||
{ return proxy.getClipboard(); }
|
||||
|
||||
public static boolean setClipboard(String text)
|
||||
{ return proxy.setClipboard(text); }
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------
|
||||
|
||||
private static final ISidedProxy proxy = DistExecutor.unsafeRunForDist(()->ClientProxy::new, ()->ServerProxy::new);
|
||||
|
@ -48,6 +52,8 @@ public class SidedProxy
|
|||
default @Nullable Minecraft mc() { return null; }
|
||||
default Optional<Boolean> isCtrlDown() { return Optional.empty(); }
|
||||
default Optional<Boolean> isShiftDown() { return Optional.empty(); }
|
||||
default Optional<String> getClipboard() { return Optional.empty(); }
|
||||
default boolean setClipboard(String text) { return false; }
|
||||
}
|
||||
|
||||
private static final class ClientProxy implements ISidedProxy
|
||||
|
@ -57,6 +63,8 @@ public class SidedProxy
|
|||
public @Nullable Minecraft mc() { return Minecraft.getInstance(); }
|
||||
public Optional<Boolean> isCtrlDown() { return Optional.of(Auxiliaries.isCtrlDown()); }
|
||||
public Optional<Boolean> isShiftDown() { return Optional.of(Auxiliaries.isShiftDown()); }
|
||||
public Optional<String> getClipboard() { return (mc()==null) ? Optional.empty() : Optional.of(net.minecraft.client.gui.font.TextFieldHelper.getClipboardContents(mc())); }
|
||||
public boolean setClipboard(String text) { if(mc()==null) {return false;} net.minecraft.client.gui.font.TextFieldHelper.setClipboardContents(Minecraft.getInstance(), text); return true; }
|
||||
}
|
||||
|
||||
private static final class ServerProxy implements ISidedProxy
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
/*
|
||||
* @file Guis.java
|
||||
* @author Stefan Wilhelm (wile)
|
||||
* @copyright (C) 2020 Stefan Wilhelm
|
||||
* @license MIT (see https://opensource.org/licenses/MIT)
|
||||
*
|
||||
* Gui Wrappers and Widgets.
|
||||
*/
|
||||
package wile.engineersdecor.libmc.ui;
|
||||
import wile.engineersdecor.libmc.detail.Auxiliaries;
|
||||
import wile.engineersdecor.libmc.detail.TooltipDisplay;
|
||||
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
|
@ -10,7 +22,6 @@ import net.minecraft.client.renderer.GameRenderer;
|
|||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import net.minecraft.client.sounds.SoundManager;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
@ -19,9 +30,8 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import wile.engineersdecor.libmc.detail.Auxiliaries;
|
||||
import wile.engineersdecor.libmc.detail.TooltipDisplay;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
@ -47,7 +57,7 @@ public class Guis
|
|||
this.player_ = player_inv.player;
|
||||
this.imageWidth = width;
|
||||
this.imageHeight = height;
|
||||
gui_background_ = new Guis.BackgroundImage(background_image_, width, height, new Coord2d(0,0));
|
||||
gui_background_ = new Guis.BackgroundImage(background_image_, width, height, Coord2d.ORIGIN);
|
||||
}
|
||||
|
||||
public ContainerGui(T menu, Inventory player_inv, Component title, String background_image)
|
||||
|
@ -55,14 +65,14 @@ public class Guis
|
|||
super(menu, player_inv, title);
|
||||
this.background_image_ = new ResourceLocation(Auxiliaries.modid(), background_image);
|
||||
this.player_ = player_inv.player;
|
||||
gui_background_ = new Guis.BackgroundImage(background_image_, imageWidth, imageHeight, new Coord2d(0,0));
|
||||
gui_background_ = new Guis.BackgroundImage(background_image_, imageWidth, imageHeight, Coord2d.ORIGIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
gui_background_.init(this, new Coord2d(0,0)).show();
|
||||
gui_background_.init(this, Coord2d.ORIGIN).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,23 +138,29 @@ public class Guis
|
|||
@OnlyIn(Dist.CLIENT)
|
||||
public static class Coord2d
|
||||
{
|
||||
public static final Coord2d ORIGIN = new Coord2d(0,0);
|
||||
public final int x, y;
|
||||
public Coord2d(int x, int y) { this.x=x; this.y=y; }
|
||||
public static Coord2d of(int x, int y) { return new Coord2d(x,y); }
|
||||
public String toString() { return "["+x+","+y+"]"; }
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class UiWidget extends net.minecraft.client.gui.components.AbstractWidget
|
||||
{
|
||||
protected static final Component EMPTY_TEXT = new TextComponent("");
|
||||
protected static final Component EMPTY_TEXT = Component.literal("");
|
||||
protected static final Function<UiWidget,Component> NO_TOOLTIP = (uiw)->EMPTY_TEXT;
|
||||
|
||||
@SuppressWarnings("all") private Function<UiWidget,Component> tooltip_ = NO_TOOLTIP;
|
||||
private final Minecraft mc_;
|
||||
private Function<UiWidget,Component> tooltip_ = NO_TOOLTIP;
|
||||
private Screen parent_;
|
||||
|
||||
public UiWidget(int x, int y, int width, int height, Component title)
|
||||
{ super(x, y, width, height, title); }
|
||||
{ super(x, y, width, height, title); mc_ = Minecraft.getInstance(); }
|
||||
|
||||
public UiWidget init(Screen parent)
|
||||
{
|
||||
this.parent_ = parent;
|
||||
this.x += ((parent instanceof AbstractContainerScreen<?>) ? ((AbstractContainerScreen<?>)parent).getGuiLeft() : 0);
|
||||
this.y += ((parent instanceof AbstractContainerScreen<?>) ? ((AbstractContainerScreen<?>)parent).getGuiTop() : 0);
|
||||
return this;
|
||||
|
@ -152,17 +168,36 @@ public class Guis
|
|||
|
||||
public UiWidget init(Screen parent, Coord2d position)
|
||||
{
|
||||
this.parent_ = parent;
|
||||
this.x = position.x + ((parent instanceof AbstractContainerScreen<?>) ? ((AbstractContainerScreen<?>)parent).getGuiLeft() : 0);
|
||||
this.y = position.y + ((parent instanceof AbstractContainerScreen<?>) ? ((AbstractContainerScreen<?>)parent).getGuiTop() : 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getWidth()
|
||||
public final UiWidget tooltip(Function<UiWidget,Component> tip)
|
||||
{ tooltip_ = tip; return this; }
|
||||
|
||||
public final UiWidget tooltip(Component tip)
|
||||
{ tooltip_ = (o)->tip; return this; }
|
||||
|
||||
public final int getWidth()
|
||||
{ return this.width; }
|
||||
|
||||
public int getHeight()
|
||||
public final int getHeight()
|
||||
{ return this.height; }
|
||||
|
||||
public Coord2d getMousePosition()
|
||||
{
|
||||
final Window win = mc_.getWindow();
|
||||
return Coord2d.of(
|
||||
Mth.clamp(((int)(mc_.mouseHandler.xpos() * (double)win.getGuiScaledWidth() / (double)win.getScreenWidth()))-this.x, -1, this.width+1),
|
||||
Mth.clamp(((int)(mc_.mouseHandler.ypos() * (double)win.getGuiScaledHeight() / (double)win.getScreenHeight()))-this.y, -1, this.height+1)
|
||||
);
|
||||
}
|
||||
|
||||
protected final Coord2d screenCoordinates(Coord2d xy, boolean reverse)
|
||||
{ return (reverse) ? (Coord2d.of(xy.x+x, xy.y+y)) : (Coord2d.of(xy.x-x, xy.y-y)); }
|
||||
|
||||
public UiWidget show()
|
||||
{ visible = true; return this; }
|
||||
|
||||
|
@ -170,18 +205,20 @@ public class Guis
|
|||
{ visible = false; return this; }
|
||||
|
||||
@Override
|
||||
public void renderButton(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks)
|
||||
public void renderButton(PoseStack mxs, int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
super.renderButton(matrixStack, mouseX, mouseY, partialTicks);
|
||||
if(isHovered) renderToolTip(matrixStack, mouseX, mouseY);
|
||||
super.renderButton(mxs, mouseX, mouseY, partialTicks);
|
||||
if(isHovered) renderToolTip(mxs, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("all")
|
||||
public void renderToolTip(PoseStack matrixStack, int mouseX, int mouseY)
|
||||
public void renderToolTip(PoseStack mx, int mouseX, int mouseY)
|
||||
{
|
||||
if(tooltip_ == NO_TOOLTIP) return;
|
||||
/// todo: need a Screen for that, not sure if adding a reference initialized in init() may cause GC problems.
|
||||
if(!visible || (!active) || (tooltip_ == NO_TOOLTIP)) return;
|
||||
final Component tip = tooltip_.apply(this);
|
||||
if(tip.getString().trim().isEmpty()) return;
|
||||
parent_.renderTooltip(mx, Arrays.asList(tip.getVisualOrderText()), mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -233,18 +270,19 @@ public class Guis
|
|||
{}
|
||||
|
||||
@Override
|
||||
public void renderButton(PoseStack mx, int mouseX, int mouseY, float partialTicks)
|
||||
public void renderButton(PoseStack mxs, int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
RenderSystem.setShaderTexture(0, atlas_);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
blit(mx, x, y, texture_position_base_.x, texture_position_base_.y, width, height);
|
||||
blit(mxs, x, y, texture_position_base_.x, texture_position_base_.y, width, height);
|
||||
if((progress_max_ > 0) && (progress_ > 0)) {
|
||||
int w = Mth.clamp((int)Math.round((progress_ * width) / progress_max_), 0, width);
|
||||
blit(mx, x, y, texture_position_filled_.x, texture_position_filled_.y, w, height);
|
||||
blit(mxs, x, y, texture_position_filled_.x, texture_position_filled_.y, w, height);
|
||||
}
|
||||
if(isHovered) renderToolTip(mxs, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,7 +309,6 @@ public class Guis
|
|||
RenderSystem.setShaderTexture(0, atlas_);
|
||||
parent.blit(mx, x, y, atlas_position_.x, atlas_position_.y, width, height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
@ -305,7 +342,7 @@ public class Guis
|
|||
{ checked_ = !checked_; on_click_.accept(this); }
|
||||
|
||||
@Override
|
||||
public void renderButton(PoseStack mx, int mouseX, int mouseY, float partialTicks)
|
||||
public void renderButton(PoseStack mxs, int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, atlas_);
|
||||
|
@ -314,9 +351,88 @@ public class Guis
|
|||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
Coord2d pos = checked_ ? texture_position_on_ : texture_position_off_;
|
||||
blit(mx, x, y, pos.x, pos.y, width, height);
|
||||
blit(mxs, x, y, pos.x, pos.y, width, height);
|
||||
if(isHovered) renderToolTip(mxs, mouseX, mouseY);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class ImageButton extends UiWidget
|
||||
{
|
||||
private final Coord2d texture_position_;
|
||||
private final ResourceLocation atlas_;
|
||||
private Consumer<ImageButton> on_click_ = (bt)->{};
|
||||
|
||||
|
||||
public ImageButton(ResourceLocation atlas, int width, int height, Coord2d atlas_texture_position)
|
||||
{
|
||||
super(0, 0, width, height, Component.empty());
|
||||
texture_position_ = atlas_texture_position;
|
||||
atlas_ = atlas;
|
||||
}
|
||||
|
||||
public ImageButton onclick(Consumer<ImageButton> action)
|
||||
{ on_click_ = action; return this; }
|
||||
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY)
|
||||
{ on_click_.accept(this); }
|
||||
|
||||
@Override
|
||||
public void renderButton(PoseStack mxs, int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, atlas_);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
Coord2d pos = texture_position_;
|
||||
blit(mxs, x, y, pos.x, pos.y, width, height);
|
||||
if(isHovered) renderToolTip(mxs, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class Image extends UiWidget
|
||||
{
|
||||
private final Coord2d texture_position_;
|
||||
private final ResourceLocation atlas_;
|
||||
|
||||
public Image(ResourceLocation atlas, int width, int height, Coord2d atlas_texture_position)
|
||||
{
|
||||
super(0, 0, width, height, Component.empty());
|
||||
texture_position_ = atlas_texture_position;
|
||||
atlas_ = atlas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY)
|
||||
{}
|
||||
|
||||
@Override
|
||||
public void renderButton(PoseStack mxs, int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, atlas_);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
Coord2d pos = texture_position_;
|
||||
blit(mxs, x, y, pos.x, pos.y, width, height);
|
||||
if(isHovered) renderToolTip(mxs, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class TextBox extends net.minecraft.client.gui.components.EditBox
|
||||
{
|
||||
public TextBox(int x, int y, int width, int height, Component title, Font font) { super(font, x, y, width, height, title); setBordered(false); }
|
||||
public TextBox withMaxLength(int len) { super.setMaxLength(len); return this; }
|
||||
public TextBox withBordered(boolean b) { super.setBordered(b); return this; }
|
||||
public TextBox withValue(String s) { super.setValue(s); return this; }
|
||||
public TextBox withEditable(boolean e) { super.setEditable(e); return this; }
|
||||
public TextBox withResponder(Consumer<String> r) { super.setResponder(r); return this; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue