Updated to 1.18.2.

This commit is contained in:
stfwi 2022-03-26 17:58:06 +01:00
parent 3f363b8d14
commit c59d1c8500
62 changed files with 1440 additions and 1445 deletions

View file

@ -25,7 +25,7 @@ repositories {
}
minecraft {
mappings channel: "official", version: "1.18.1"
mappings channel: "official", version: "1.18.2"
runs {
client {
workingDirectory project.file('run')

View file

@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx8G
meta_modid=engineersdecor
meta_issues=https://github.com/stfwi/engineers-decor/issues
meta_download=https://www.curseforge.com/minecraft/mc-mods/engineers-decor/
version_minecraft=1.18.1
version_forge_minecraft=1.18.1-39.0.5
version_jei=1.18.1:9.1.2.54
version_engineersdecor=1.1.21
version_minecraft=1.18.2
version_forge_minecraft=1.18.2-40.0.32
version_jei=1.18.2:9.5.4.171
version_engineersdecor=1.1.22-b1

View file

@ -1,6 +1,7 @@
{
"homepage": "https://www.curseforge.com/minecraft/mc-mods/engineers-decor/",
"1.18.1": {
"1.18.2": {
"1.1.22-b1": "[U] Updated to 1.18.2.",
"1.1.21": "[A] Added French translation (PR#203, dracnis).",
"1.1.20": "[F] Fixed Shingle Roof Wire Conduit collision shape (thx os, issue #202).\n[F] Mineral Melter accepts input items only when empty (issue #198, ty Archie).",
"1.1.19": "[R] Release build.\n[F] Manual category RLs prefixed (issue #199, ty freopt).",
@ -52,7 +53,7 @@
"1.1.2-b1": "[U] Ported to MC1.16.2."
},
"promos": {
"1.18.1-recommended": "1.1.21",
"1.18.1-latest": "1.1.21"
"1.18.2-recommended": "1.1.21",
"1.18.2-latest": "1.1.22-b1"
}
}

View file

@ -11,6 +11,8 @@ Mod sources for Minecraft version 1.18.x.
## Version history
- v1.1.22-b1 [U] Updated to 1.18.2.
- v1.1.21 [A] Added French translation (PR#203, dracnis).
- v1.1.20 [F] Fixed Shingle Roof Wire Conduit collision shape (thx os, issue #202).

View file

@ -321,7 +321,7 @@ public class ModConfig
//--------------------------------------------------------------------------------------------------------------------
public static boolean isOptedOut(final @Nullable Block block)
{ return isOptedOut(block.asItem()); }
{ return (block==null) || isOptedOut(block.asItem()); }
public static boolean isOptedOut(final @Nullable Item item)
{ return (item!=null) && optouts_.contains(item.getRegistryName().getPath()); }
@ -379,12 +379,9 @@ public class ModConfig
if(!includes.isEmpty()) log("Config pattern includes: '" + String.join(",", includes) + "'");
{
HashSet<String> optouts = new HashSet<>();
ModContent.getRegisteredItems().stream().filter(Objects::nonNull).forEach(
e -> optouts.add(e.getRegistryName().getPath())
);
ModContent.getRegisteredBlocks().stream().filter((Block block) -> {
if(block==null) return true;
if(block==ModContent.SIGN_MODLOGO) return true;
if(block==ModContent.getBlock("sign_decor")) return true;
try {
if(!with_experimental_features_) {
if(block instanceof Auxiliaries.IExperimentalFeature) return true;

File diff suppressed because it is too large Load diff

View file

@ -3,13 +3,9 @@ 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.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.event.RegistryEvent;
@ -26,6 +22,7 @@ import org.apache.logging.log4j.Logger;
import wile.engineersdecor.blocks.EdLadderBlock;
import wile.engineersdecor.libmc.detail.Auxiliaries;
import wile.engineersdecor.libmc.detail.OptionalRecipeCondition;
import wile.engineersdecor.libmc.detail.Registries;
@Mod("engineersdecor")
@ -40,6 +37,8 @@ public class ModEngineersDecor
{
Auxiliaries.init(MODID, LOGGER, ModConfig::getServerConfig);
Auxiliaries.logGitVersion(MODNAME);
Registries.init(MODID, "sign_decor");
ModContent.init(MODID);
OptionalRecipeCondition.init(MODID, LOGGER);
ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.SERVER, ModConfig.SERVER_CONFIG_SPEC);
ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.COMMON, ModConfig.COMMON_CONFIG_SPEC);
@ -63,8 +62,8 @@ public class ModEngineersDecor
private void onClientSetup(final FMLClientSetupEvent event)
{
ModContent.registerContainerGuis(event);
ModContent.registerTileEntityRenderers(event);
ModContent.registerMenuGuis(event);
ModContent.registerBlockEntityRenderers(event);
ModContent.processContentClientSide(event);
wile.engineersdecor.libmc.detail.Overlay.register();
}
@ -73,24 +72,24 @@ public class ModEngineersDecor
public static class ForgeEvents
{
@SubscribeEvent
public static void onBlocksRegistry(final RegistryEvent.Register<Block> event)
public static void onRegisterBlocks(final RegistryEvent.Register<Block> event)
{ ModContent.registerBlocks(event); }
@SubscribeEvent
public static void onItemRegistry(final RegistryEvent.Register<Item> event)
{ ModContent.registerItems(event); ModContent.registerBlockItems(event); }
public static void onRegisterItems(final RegistryEvent.Register<Item> event)
{ ModContent.registerItems(event); }
@SubscribeEvent
public static void onTileEntityRegistry(final RegistryEvent.Register<BlockEntityType<?>> event)
{ ModContent.registerTileEntities(event); }
public static void onRegisterBlockEntityTypes(final RegistryEvent.Register<BlockEntityType<?>> event)
{ ModContent.registerBlockEntityTypes(event); }
@SubscribeEvent
public static void onRegisterEntityTypes(final RegistryEvent.Register<EntityType<?>> event)
{ ModContent.registerEntities(event); }
{ ModContent.registerEntityTypes(event); }
@SubscribeEvent
public static void onRegisterContainerTypes(final RegistryEvent.Register<MenuType<?>> event)
{ ModContent.registerContainers(event); }
public static void onRegisterMenuTypes(final RegistryEvent.Register<MenuType<?>> event)
{ ModContent.registerMenuTypes(event); }
@SubscribeEvent
public static void onConfigLoad(final ModConfigEvent.Loading event)
@ -108,15 +107,6 @@ public class ModEngineersDecor
}
}
//
// Item group / creative tab
//
public static final CreativeModeTab ITEMGROUP = (new CreativeModeTab("tab" + MODID) {
@OnlyIn(Dist.CLIENT)
public ItemStack makeIcon()
{ return new ItemStack(ModContent.SIGN_MODLOGO); }
});
//
// Player update event
//

View file

@ -12,6 +12,7 @@ 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;
@ -30,7 +31,6 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -93,10 +93,9 @@ public class EdBreaker
public BreakerBlock(long config, BlockBehaviour.Properties builder, final AABB[] unrotatedAABBs)
{ super(config, builder, unrotatedAABBs); }
@Nullable
@Override
public BlockEntityType<BreakerTileEntity> getBlockEntityType()
{ return ModContent.TET_SMALL_BLOCK_BREAKER; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -117,7 +116,7 @@ public class EdBreaker
{
if((state.getBlock()!=this) || (!state.getValue(ACTIVE))) return;
// Sound
if(true || (world.getGameTime() & 0x1) == 0) {
{
SoundEvent sound = SoundEvents.WOOD_HIT;
BlockState target_state = world.getBlockState(pos.relative(state.getValue(BreakerBlock.HORIZONTAL_FACING)));
SoundType stype = target_state.getBlock().getSoundType(target_state);
@ -196,7 +195,7 @@ public class EdBreaker
private final LazyOptional<IEnergyStorage> energy_handler_ = battery_.createEnergyHandler();
public BreakerTileEntity(BlockPos pos, BlockState state)
{ super(ModContent.TET_SMALL_BLOCK_BREAKER, pos, state); }
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
public void block_updated()
{ if(tick_timer_ > 2) tick_timer_ = 2; }
@ -284,7 +283,7 @@ public class EdBreaker
// Maybe make a tag for that. The question is if it is actually worth it, or if that would be only
// tag spamming the game. So for now only FH and VH.
final BlockState state = world.getBlockState(pos);
return (state.getBlock() == ModContent.FACTORY_HOPPER) || (state.getBlock() == Blocks.HOPPER);
return (state.getBlock() == ModContent.getBlock("factory_hopper")) || (state.getBlock() == Blocks.HOPPER);
}
private boolean breakBlock(BlockState state, BlockPos pos, Level world)

View file

@ -131,7 +131,7 @@ public class EdCatwalkBlock extends StandardBlocks.HorizontalFourWayWaterLoggabl
List<ItemStack> drops = new ArrayList<>();
drops.add(new ItemStack(state.getBlock().asItem()));
int n = (state.getValue(NORTH)?1:0)+(state.getValue(EAST)?1:0)+(state.getValue(SOUTH)?1:0)+(state.getValue(WEST)?1:0);
if(n > 0) drops.add(new ItemStack(ModContent.STEEL_RAILING, n));
if(n > 0) drops.add(new ItemStack(ModContent.getBlock("steel_railing"), n));
return drops;
}

View file

@ -127,17 +127,17 @@ public class EdCatwalkStairsBlock extends StandardBlocks.HorizontalWaterLoggable
place_state = place_state.setValue(WATERLOGGED,adjacent_state.getFluidState().getType()==Fluids.WATER);
EdCatwalkBlock.place_consume(place_state, world, adjacent_pos, player, hand, 1);
return world.isClientSide() ? InteractionResult.SUCCESS : InteractionResult.CONSUME;
} else if((block == ModContent.STEEL_CATWALK) || (block == ModContent.STEEL_CATWALK_TOP_ALIGNED)) {
} else if((block == ModContent.getBlock("steel_catwalk")) || (block == ModContent.getBlock("steel_catwalk_ta"))) {
BlockPos adjacent_pos;
adjacent_pos = pos.relative(facing);
final BlockState adjacent_state = world.getBlockState(adjacent_pos);
if(adjacent_state == null) return InteractionResult.CONSUME;
if(!adjacent_state.canBeReplaced(new DirectionalPlaceContext(world, adjacent_pos, hit.getDirection().getOpposite(), player.getItemInHand(hand), hit.getDirection()))) return InteractionResult.CONSUME;
BlockState place_state = ModContent.STEEL_CATWALK_TOP_ALIGNED.defaultBlockState();
BlockState place_state = ModContent.getBlock("steel_catwalk_ta").defaultBlockState(); // ModContent.STEEL_CATWALK_TOP_ALIGNED
place_state = place_state.setValue(WATERLOGGED,adjacent_state.getFluidState().getType()==Fluids.WATER);
EdCatwalkBlock.place_consume(place_state, world, adjacent_pos, player, hand, 1);
return world.isClientSide() ? InteractionResult.SUCCESS : InteractionResult.CONSUME;
} else if(block == ModContent.STEEL_RAILING) {
} else if(block == ModContent.getBlock("steel_railing")) {
Direction face = hit.getDirection();
int shrink = 0;
BlockState place_state = state;
@ -179,7 +179,7 @@ public class EdCatwalkStairsBlock extends StandardBlocks.HorizontalWaterLoggable
List<ItemStack> drops = new ArrayList<>();
drops.add(new ItemStack(state.getBlock().asItem()));
int n = (state.getValue(LEFT_RAILING)?1:0)+(state.getValue(RIGHT_RAILING)?1:0);
if(n > 0) drops.add(new ItemStack(ModContent.STEEL_RAILING, n));
if(n > 0) drops.add(new ItemStack(ModContent.getBlock("steel_railing"), n));
return drops;
}

View file

@ -103,8 +103,8 @@ public class EdCatwalkTopAlignedBlock extends StandardBlocks.WaterLoggable
{
BlockState below = world.getBlockState(pos.below());
if((below == null) || (state == null)) return state;
if((below.getBlock() == ModContent.THICK_STEEL_POLE) || (below.getBlock() == ModContent.THICK_STEEL_POLE_HEAD)) return state.setValue(VARIANT, 1);
if((below.getBlock() == ModContent.THIN_STEEL_POLE) || (below.getBlock() == ModContent.THIN_STEEL_POLE_HEAD)) return state.setValue(VARIANT, 2);
if((below.getBlock() == ModContent.getBlock("thick_steel_pole")) || (below.getBlock() == ModContent.getBlock("thick_steel_pole_head"))) return state.setValue(VARIANT, 1);
if((below.getBlock() == ModContent.getBlock("thin_steel_pole")) || (below.getBlock() == ModContent.getBlock("thin_steel_pole_head"))) return state.setValue(VARIANT, 2);
return state;
}

View file

@ -114,7 +114,7 @@ public class EdChair
}
public EntityChair(Level world)
{ this(ModContent.ET_CHAIR, world); }
{ this(ModContent.getEntityType("et_chair"), world); }
public static EntityChair customClientFactory(PlayMessages.SpawnEntity spkt, Level world)
{ return new EntityChair(world); }

View file

@ -36,14 +36,13 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.ticks.TickPriority;
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.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.ticks.TickPriority;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.ForgeEventFactory;
@ -93,10 +92,9 @@ public class EdCraftingTable
public CraftingTableBlock(long config, BlockBehaviour.Properties builder, final AABB[] unrotatedAABBs)
{ super(config, builder, unrotatedAABBs); }
@Nullable
@Override
public BlockEntityType<EdCraftingTable.CraftingTableTileEntity> getBlockEntityType()
{ return ModContent.TET_CRAFTING_TABLE; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -179,7 +177,7 @@ public class EdCraftingTable
public CraftingTableTileEntity(BlockPos pos, BlockState state)
{
super(ModContent.TET_CRAFTING_TABLE, pos, state);
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
inventory_ = new StorageInventory(this, NUM_OF_SLOTS, 1);
inventory_.setCloseAction((player)->{
if(getLevel() instanceof Level) {
@ -329,7 +327,7 @@ public class EdCraftingTable
private CraftingTableUiContainer(int cid, Inventory pinv, Container block_inventory, ContainerLevelAccess wpc)
{
super(ModContent.CT_TREATED_WOOD_CRAFTING_TABLE, cid);
super(ModContent.getMenuType("metal_crafting_table"), cid); // @todo: class mapping, this stuff is continuously changed to break mods.
wpc_ = wpc;
player_ = pinv.player;
inventory_ = block_inventory;
@ -463,7 +461,7 @@ public class EdCraftingTable
super.clicked(slotId, button, clickType, player);
if((with_outslot_defined_refab) && (slotId == 0) && (clickType == ClickType.PICKUP)) {
if((!crafting_matrix_changed_now_) && (!player.level.isClientSide()) && (crafting_grid_empty())) {
final ItemStack dragged = player.inventoryMenu.getCarried();
final ItemStack dragged = getCarried();
if((dragged != null) && (!dragged.isEmpty())) {
try_result_stack_refab(dragged, player.level);
} else if(!history().current().isEmpty()) {
@ -803,6 +801,9 @@ public class EdCraftingTable
if(recipe != null) {
sync();
onCraftMatrixChanged();
} else {
history().reset_current();
sync();
}
}
@ -1048,7 +1049,8 @@ public class EdCraftingTable
}
{
List<TipRange> tooltips = new ArrayList<>();
final String prefix = ModContent.CRAFTING_TABLE.getDescriptionId() + ".tooltips.";
final Block block = ModContent.getBlock(getMenu().getType().getRegistryName().getPath().replaceAll("^ct_",""));
final String prefix = block.getDescriptionId() + ".tooltips.";
String[] translation_keys = { "next", "prev", "clear", "nextcollisionrecipe", "fromstorage", "tostorage", "fromplayer", "toplayer" };
for(int i=0; (i<buttons.size()) && (i<translation_keys.length); ++i) {
Button bt = buttons.get(i);

View file

@ -15,6 +15,7 @@ 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;
@ -32,7 +33,6 @@ 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.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -54,9 +54,12 @@ 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.*;
import wile.engineersdecor.libmc.detail.Auxiliaries;
import wile.engineersdecor.libmc.detail.Inventories;
import wile.engineersdecor.libmc.detail.Inventories.InventoryRange;
import wile.engineersdecor.libmc.detail.Inventories.StorageInventory;
import wile.engineersdecor.libmc.detail.Networking;
import wile.engineersdecor.libmc.detail.RsSignals;
import wile.engineersdecor.libmc.detail.TooltipDisplay.TipRange;
import wile.engineersdecor.libmc.ui.Guis;
@ -88,10 +91,9 @@ public class EdDropper
public DropperBlock(long config, BlockBehaviour.Properties builder, final AABB unrotatedAABB)
{ super(config, builder, unrotatedAABB); }
@Nullable
@Override
public BlockEntityType<EdDropper.DropperTileEntity> getBlockEntityType()
{ return ModContent.TET_FACTORY_DROPPER; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -231,7 +233,7 @@ public class EdDropper
protected LazyOptional<? extends IItemHandler> item_handler_ = Inventories.MappedItemHandler.createGenericHandler(storage_slot_range_);
public DropperTileEntity(BlockPos pos, BlockState state)
{ super(ModContent.TET_FACTORY_DROPPER, pos, state); reset_rtstate(); }
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); reset_rtstate(); }
public CompoundTag clear_getnbt()
{
@ -646,7 +648,7 @@ public class EdDropper
private DropperUiContainer(int cid, Inventory player_inventory, Container block_inventory, ContainerLevelAccess wpc, ContainerData fields)
{
super(ModContent.CT_FACTORY_DROPPER, cid);
super(ModContent.getMenuType("factory_dropper"), cid); // @todo: class mapping
fields_ = fields;
wpc_ = wpc;
player_ = player_inventory.player;
@ -785,7 +787,8 @@ public class EdDropper
{
super.init();
{
final String prefix = ModContent.FACTORY_DROPPER.getDescriptionId() + ".tooltips.";
final Block block = ModContent.getBlock(getMenu().getType().getRegistryName().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")),

View file

@ -15,6 +15,7 @@ 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;
@ -35,7 +36,6 @@ import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -91,10 +91,9 @@ public class EdElectricalFurnace
public ElectricalFurnaceBlock(long config, BlockBehaviour.Properties builder, final AABB[] unrotatedAABBs)
{ super(config, builder, unrotatedAABBs); }
@Nullable
@Override
public BlockEntityType<EdElectricalFurnace.ElectricalFurnaceTileEntity> getBlockEntityType()
{ return ModContent.TET_SMALL_ELECTRICAL_FURNACE; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -252,7 +251,7 @@ public class EdElectricalFurnace
public ElectricalFurnaceTileEntity(BlockPos pos, BlockState state)
{
super(ModContent.TET_SMALL_ELECTRICAL_FURNACE, pos, state);
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
inventory_ = new StorageInventory(this, NUM_OF_SLOTS) {
@Override
public void setItem(int index, ItemStack stack)
@ -497,7 +496,7 @@ public class EdElectricalFurnace
// Furnace --------------------------------------------------------------------------------------
private boolean is_accepted_hopper(final ItemStack stack)
{ return (stack.getItem() == Blocks.HOPPER.asItem()) || (stack.getItem() == ModContent.FACTORY_HOPPER.asItem()); }
{ return (stack.getItem() == Blocks.HOPPER.asItem()) || (stack.getItem() == ModContent.getBlock("factory_hopper").asItem()); }
private boolean transferItems(final int index_from, final int index_to, int count)
{
@ -758,7 +757,7 @@ public class EdElectricalFurnace
private ElectricalFurnaceContainer(int cid, Inventory player_inventory, Container block_inventory, ContainerLevelAccess wpc, ContainerData fields)
{
super(ModContent.CT_SMALL_ELECTRICAL_FURNACE, cid);
super(ModContent.getMenuType("small_electrical_furnace"), cid); // @todo: class mapping,
player_ = player_inventory.player;
inventory_ = block_inventory;
wpc_ = wpc;
@ -869,7 +868,8 @@ public class EdElectricalFurnace
public void init()
{
super.init();
final String prefix = ModContent.SMALL_ELECTRICAL_FURNACE.getDescriptionId() + ".tooltips.";
final Block block = ModContent.getBlock(getMenu().getType().getRegistryName().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(

View file

@ -11,8 +11,10 @@ package wile.engineersdecor.blocks;
import net.minecraft.core.BlockPos;
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;
@ -32,7 +34,6 @@ 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.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -47,7 +48,6 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraft.nbt.Tag;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
@ -99,10 +99,9 @@ public class EdFluidBarrel
registerDefaultState(super.defaultBlockState().setValue(FACING, Direction.UP).setValue(FILL_LEVEL, 0));
}
@Nullable
@Override
public BlockEntityType<EdFluidBarrel.FluidBarrelTileEntity> getBlockEntityType()
{ return ModContent.TET_FLUID_BARREL; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -226,7 +225,7 @@ public class EdFluidBarrel
private final LazyOptional<IFluidHandler> fluid_handler_ = tank_.createFluidHandler();
public FluidBarrelTileEntity(BlockPos pos, BlockState state)
{ super(ModContent.TET_FLUID_BARREL, pos, state); }
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
public void readnbt(CompoundTag nbt)
{ tank_.load(nbt); }

View file

@ -14,6 +14,7 @@ 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;
@ -27,7 +28,6 @@ import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -77,10 +77,9 @@ public class EdFluidFunnel
public FluidFunnelBlock(long config, BlockBehaviour.Properties builder, final AABB[] unrotatedAABB)
{ super(config, builder, unrotatedAABB); }
@Nullable
@Override
public BlockEntityType<EdFluidFunnel.FluidFunnelTileEntity> getBlockEntityType()
{ return ModContent.TET_SMALL_FLUID_FUNNEL; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -196,7 +195,7 @@ public class EdFluidFunnel
private final LazyOptional<IFluidHandler> fluid_handler_ = tank_.createOutputFluidHandler();
public FluidFunnelTileEntity(BlockPos pos, BlockState state)
{ super(ModContent.TET_SMALL_FLUID_FUNNEL, pos, state); }
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
public void readnbt(CompoundTag nbt)
{

View file

@ -12,6 +12,7 @@ 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;
@ -27,7 +28,6 @@ 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.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -76,10 +76,9 @@ public class EdFreezer
public FreezerBlock(long config, BlockBehaviour.Properties builder, final AABB unrotatedAABB)
{ super(config, builder, unrotatedAABB); }
@Nullable
@Override
public BlockEntityType<EdFreezer.FreezerTileEntity> getBlockEntityType()
{ return ModContent.TET_FREEZER; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -208,7 +207,7 @@ public class EdFreezer
}
public FreezerTileEntity(BlockPos pos, BlockState state)
{ super(ModContent.TET_FREEZER, pos, state); }
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
public int progress()
{ return progress_; }

View file

@ -38,7 +38,6 @@ 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.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -90,9 +89,8 @@ public class EdFurnace
{ super(config, properties, unrotatedAABB); registerDefaultState(super.defaultBlockState().setValue(LIT, false)); }
@Override
@Nullable
public BlockEntityType<EdFurnace.FurnaceTileEntity> getBlockEntityType()
{ return ModContent.TET_SMALL_LAB_FURNACE; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -278,7 +276,7 @@ public class EdFurnace
public FurnaceTileEntity(BlockPos pos, BlockState state)
{
super(ModContent.TET_SMALL_LAB_FURNACE, pos, state);
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
inventory_ = new StorageInventory(this, NUM_OF_SLOTS) {
@Override
public void setItem(int index, ItemStack stack)
@ -763,7 +761,7 @@ public class EdFurnace
private FurnaceContainer(int cid, Inventory player_inventory, Container block_inventory, ContainerLevelAccess wpc, ContainerData fields)
{
super(ModContent.CT_SMALL_LAB_FURNACE, cid);
super(ModContent.getMenuType("small_lab_furnace"), cid); // @todo: class mapping
player_ = player_inventory.player;
inventory_ = block_inventory;
wpc_ = wpc;

View file

@ -15,6 +15,7 @@ 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;
@ -30,7 +31,6 @@ 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.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
@ -71,9 +71,8 @@ public class EdHopper
{ super(config, builder, shape_supplier); }
@Override
@Nullable
public BlockEntityType<EdHopper.HopperTileEntity> getBlockEntityType()
{ return ModContent.TET_FACTORY_HOPPER; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -216,7 +215,7 @@ public class EdHopper
public HopperTileEntity(BlockPos pos, BlockState state)
{
super(ModContent.TET_FACTORY_HOPPER, pos, state);
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
main_inventory_.setSlotChangeAction((slot,stack)->tick_timer_ = Math.min(tick_timer_, 8));
}
@ -631,7 +630,7 @@ public class EdHopper
private HopperContainer(int cid, Inventory player_inventory, Container block_inventory, ContainerLevelAccess wpc, ContainerData fields)
{
super(ModContent.CT_FACTORY_HOPPER, cid);
super(ModContent.getMenuType("factory_hopper"), cid); // @todo: class mapping
fields_ = fields;
wpc_ = wpc;
player_ = player_inventory.player;
@ -761,7 +760,8 @@ public class EdHopper
{
super.init();
{
final String prefix = ModContent.FACTORY_HOPPER.getDescriptionId() + ".tooltips.";
final Block block = ModContent.getBlock(getMenu().getType().getRegistryName().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")),

View file

@ -119,9 +119,9 @@ public class EdHorizontalSupportBlock extends StandardBlocks.WaterLoggable
if((dstate.getBlock() instanceof final EdStraightPoleBlock pole)) {
final Direction dfacing = dstate.getValue(EdStraightPoleBlock.FACING);
if((dfacing.getAxis() == Direction.Axis.Y)) {
if((pole== ModContent.THICK_STEEL_POLE) || ((pole==ModContent.THICK_STEEL_POLE_HEAD) && (dfacing==Direction.UP))) {
if((pole==ModContent.getBlock("thick_steel_pole")) || ((pole==ModContent.getBlock("thick_steel_pole_head")) && (dfacing==Direction.UP))) {
down_connector = 2;
} else if((pole==ModContent.THIN_STEEL_POLE) || ((pole==ModContent.THIN_STEEL_POLE_HEAD) && (dfacing==Direction.UP))) {
} else if((pole==ModContent.getBlock("thin_steel_pole")) || ((pole==ModContent.getBlock("thin_steel_pole_head")) && (dfacing==Direction.UP))) {
down_connector = 1;
}
}

View file

@ -13,11 +13,13 @@ 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;
@ -33,7 +35,6 @@ 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.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;
@ -41,7 +42,6 @@ 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.minecraft.nbt.Tag;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
@ -71,7 +71,7 @@ public class EdLabeledCrate
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.LABELED_CRATE.asItem());
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(",")));
}
@ -86,9 +86,8 @@ public class EdLabeledCrate
{ super(config, builder, unrotatedAABB); }
@Override
@Nullable
public BlockEntityType<EdLabeledCrate.LabeledCrateTileEntity> getBlockEntityType()
{ return ModContent.TET_LABELED_CRATE; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -171,7 +170,7 @@ public class EdLabeledCrate
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, "Items", LabeledCrateTileEntity.NUM_OF_SLOTS);
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<>();
@ -224,7 +223,7 @@ public class EdLabeledCrate
public LabeledCrateTileEntity(BlockPos pos, BlockState state)
{
super(ModContent.TET_LABELED_CRATE, pos, 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()));
@ -422,7 +421,7 @@ public class EdLabeledCrate
private LabeledCrateContainer(int cid, Inventory player_inventory, Container block_inventory, ContainerLevelAccess wpc, ContainerData fields)
{
super(ModContent.CT_LABELED_CRATE, cid);
super(ModContent.getMenuType("labeled_crate"), cid); // @todo: class mapping
player_ = player_inventory.player;
inventory_ = block_inventory;
wpc_ = wpc;

View file

@ -32,7 +32,6 @@ 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.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -122,9 +121,8 @@ public class EdMilker
}
@Override
@Nullable
public BlockEntityType<EdMilker.MilkerTileEntity> getBlockEntityType()
{ return ModContent.TET_SMALL_MILKING_MACHINE; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -222,7 +220,7 @@ public class EdMilker
public MilkerTileEntity(BlockPos pos, BlockState state)
{
super(ModContent.TET_SMALL_MILKING_MACHINE, pos, state);
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), 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);
@ -718,8 +716,8 @@ public class EdMilker
@Override
public void tick()
{
BlockPos testpos = new BlockPos(target_pos_.x(), mob.position().y(), target_pos_.z());
if(!testpos.closerThan(mob.position(), acceptedDistance())) {
final BlockPos testpos = new BlockPos(target_pos_.x(), mob.position().y(), target_pos_.z());
if(!testpos.closerToCenterThan(mob.position(), acceptedDistance())) {
if((++tryTicks > motion_timeout)) {
log("tick() -> abort, timeoutCounter");
abort();

View file

@ -32,7 +32,6 @@ import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -83,9 +82,8 @@ public class EdMineralSmelter
{ super(config, builder, unrotatedAABB); }
@Override
@Nullable
public BlockEntityType<EdMineralSmelter.MineralSmelterTileEntity> getBlockEntityType()
{ return ModContent.TET_MINERAL_SMELTER; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -274,7 +272,7 @@ public class EdMineralSmelter
public MineralSmelterTileEntity(BlockPos pos, BlockState state)
{
super(ModContent.TET_MINERAL_SMELTER, pos, state);
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
main_inventory_ = (new Inventories.StorageInventory(this, NUM_OF_SLOTS, 1)).setStackLimit(1);
item_handler_ = Inventories.MappedItemHandler.createGenericHandler(
main_inventory_,
@ -312,8 +310,7 @@ public class EdMineralSmelter
} else if(bucket_extraction_possible()) {
return accepts_lava_container(stack);
} else {
if(stack.getItem().getTags().contains(new ResourceLocation(Auxiliaries.modid(), "accepted_mineral_smelter_input"))) return true;
return accepted_minerals.contains(stack.getItem());
return (accepted_minerals.contains(stack.getItem())) || (Auxiliaries.isInItemTag(stack.getItem(), new ResourceLocation(Auxiliaries.modid(), "accepted_mineral_smelter_input")));
}
}

View file

@ -11,6 +11,7 @@ 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;
@ -75,10 +76,17 @@ 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 BlockEntityType<EdPipeValve.PipeValveTileEntity> getBlockEntityType()
{ return ModContent.TET_STRAIGHT_PIPE_VALVE; }
public BlockEntity newBlockEntity(BlockPos pos, BlockState state)
{
final BlockEntityType<?> tet = ModContent.getBlockEntityTypeOfBlock("straight_pipe_valve");
return (tet==null) ? null : tet.create(pos, state);
}
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -175,7 +183,7 @@ public class EdPipeValve
private int valve_config_;
public PipeValveTileEntity(BlockPos pos, BlockState state)
{ super(ModContent.TET_STRAIGHT_PIPE_VALVE, pos, state); }
{ super(ModContent.getBlockEntityTypeOfBlock("straight_pipe_valve"), pos, state); }
private Direction block_facing()
{

View file

@ -15,6 +15,7 @@ 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;
@ -38,7 +39,6 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluids;
@ -84,9 +84,8 @@ public class EdPlacer
{ super(config, builder, unrotatedAABB); }
@Override
@Nullable
public BlockEntityType<EdPlacer.PlacerTileEntity> getBlockEntityType()
{ return ModContent.TET_FACTORY_PLACER; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -201,12 +200,13 @@ public class EdPlacer
private int logic_ = LOGIC_IGNORE_EXT|LOGIC_CONTINUOUS;
private int current_slot_index_ = 0;
private int tick_timer_ = 0;
private final boolean debug_ = false; // @todo debug stick in `self::use()` toggling.
private final Inventories.StorageInventory inventory_ = new Inventories.StorageInventory(this, NUM_OF_SLOTS, 1);
private final LazyOptional<IItemHandler> item_handler_;
public PlacerTileEntity(BlockPos pos, BlockState state)
{
super(ModContent.TET_FACTORY_PLACER, pos, state);
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
item_handler_ = Inventories.MappedItemHandler.createGenericHandler(inventory_,
(stack, slot) -> true,
(stack, slot) -> true
@ -383,7 +383,7 @@ public class EdPlacer
Block block = Block.byItem(item);
if(block == Blocks.AIR) {
if(item != null) {
Auxiliaries.logDebug("Placer spit: No block for item " + item.getRegistryName().toString());
if(debug_) Auxiliaries.logInfo("Placer spit: No block for item " + item.getRegistryName().toString());
return spit_out(facing); // Item not accepted
}
} else if(block instanceof IPlantable) {
@ -459,7 +459,7 @@ public class EdPlacer
}
BlockState placement_state = (use_context==null) ? (block.defaultBlockState()) : (block.getStateForPlacement(use_context));
if(placement_state == null) {
Auxiliaries.logDebug("Placer spit: No valid placement state for item " + item.getRegistryName().toString());
if(debug_) Auxiliaries.logInfo("Placer spit: No valid placement state for item " + item.getRegistryName().toString());
return spit_out(facing);
} else if((use_context!=null) && (item instanceof BlockItem)) {
if(((BlockItem)item).place(use_context) != InteractionResult.FAIL) {
@ -554,7 +554,7 @@ public class EdPlacer
private PlacerContainer(int cid, Inventory player_inventory, Container block_inventory, ContainerLevelAccess wpc, ContainerData fields)
{
super(ModContent.CT_FACTORY_PLACER, cid);
super(ModContent.getMenuType("factory_placer"), cid); // @todo: class mapping
fields_ = fields;
wpc_ = wpc;
player_ = player_inventory.player;
@ -683,7 +683,8 @@ public class EdPlacer
{
super.init();
{
final String prefix = ModContent.FACTORY_PLACER.getDescriptionId() + ".tooltips.";
final Block block = ModContent.getBlock(getMenu().getType().getRegistryName().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")),

View file

@ -11,6 +11,7 @@ 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;
@ -20,7 +21,6 @@ import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.LightLayer;
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.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -77,9 +77,8 @@ public class EdSolarPanel
}
@Override
@Nullable
public BlockEntityType<EdSolarPanel.SolarPanelTileEntity> getBlockEntityType()
{ return ModContent.TET_SMALL_SOLAR_PANEL; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -126,7 +125,7 @@ public class EdSolarPanel
//------------------------------------------------------------------------------------------------------------------
public SolarPanelTileEntity(BlockPos pos, BlockState state)
{ super(ModContent.TET_SMALL_SOLAR_PANEL, pos, state); }
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
public void readnbt(CompoundTag nbt, boolean update_packet)
{ battery_.load(nbt); }

View file

@ -12,6 +12,7 @@ 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.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
@ -22,7 +23,6 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluids;
@ -63,9 +63,8 @@ public class EdTestBlock
{ super(config, builder, unrotatedAABB); }
@Override
@Nullable
public BlockEntityType<EdTestBlock.TestTileEntity> getBlockEntityType()
{ return ModContent.TET_TEST_BLOCK; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -137,7 +136,7 @@ public class EdTestBlock
public TestTileEntity(BlockPos pos, BlockState state)
{
super(ModContent.TET_TEST_BLOCK, pos, state);
super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state);
battery_ = new RfEnergy.Battery((int)1e9, (int)1e9, 0, 0);
energy_handler_ = battery_.createEnergyHandler();
tank_ = new Fluidics.Tank((int)1e9);
@ -248,7 +247,7 @@ public class EdTestBlock
Overlay.show(player, new TextComponent("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.FACTORY_HOPPER) {
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);
}
@ -306,7 +305,7 @@ public class EdTestBlock
if((tick_timer == 1) && (!insertion_item.isEmpty())) {
BlockState adjacent_state = level.getBlockState(worldPosition.relative(block_facing));
ItemStack stack = (insertion_item.getItem()==Items.LEVER) ? getRandomItemstack() : insertion_item.copy();
if(adjacent_state.getBlock()==Blocks.HOPPER || adjacent_state.getBlock()==ModContent.FACTORY_HOPPER) {
if(adjacent_state.getBlock()==Blocks.HOPPER || adjacent_state.getBlock()==ModContent.getBlock("factory_hopper")) {
ItemStack remaining = Inventories.insert(getLevel(), getBlockPos().relative(block_facing), block_facing.getOpposite(), stack, false);
int n = stack.getCount() - remaining.getCount();
items_inserted_total += n;

View file

@ -12,6 +12,7 @@ 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;
@ -23,7 +24,6 @@ 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.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -65,9 +65,8 @@ public class EdTreeCutter
{ super(config, builder, unrotatedAABB); }
@Override
@Nullable
public BlockEntityType<EdTreeCutter.TreeCutterTileEntity> getBlockEntityType()
{ return ModContent.TET_SMALL_TREE_CUTTER; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -152,7 +151,7 @@ public class EdTreeCutter
}
public TreeCutterTileEntity(BlockPos pos, BlockState state)
{ super(ModContent.TET_SMALL_TREE_CUTTER, pos, state); }
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); }
public void readnbt(CompoundTag nbt)
{ energy_ = nbt.getInt("energy"); }

View file

@ -14,6 +14,7 @@ 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;
@ -28,7 +29,6 @@ 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.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -83,9 +83,8 @@ public class EdWasteIncinerator
{ super(config, builder, unrotatedAABB); }
@Override
@Nullable
public BlockEntityType<EdWasteIncinerator.WasteIncineratorTileEntity> getBlockEntityType()
{ return ModContent.TET_WASTE_INCINERATOR; }
public ResourceLocation getBlockRegistryName()
{ return getRegistryName(); }
@Override
public boolean isBlockEntityTicking(Level world, BlockState state)
@ -195,7 +194,7 @@ public class EdWasteIncinerator
private final LazyOptional<IEnergyStorage> energy_handler_ = battery_.createEnergyHandler();
public WasteIncineratorTileEntity(BlockPos pos, BlockState state)
{ super(ModContent.TET_WASTE_INCINERATOR, pos, state); reset(); }
{ super(ModContent.getBlockEntityTypeOfBlock(state.getBlock().getRegistryName().getPath()), pos, state); reset(); }
public CompoundTag getnbt()
{ return writenbt(new CompoundTag()); }
@ -414,7 +413,7 @@ public class EdWasteIncinerator
private WasteIncineratorContainer(int cid, Inventory player_inventory, Container block_inventory, ContainerLevelAccess wpc, ContainerData fields)
{
super(ModContent.CT_WASTE_INCINERATOR, cid);
super(ModContent.getMenuType("small_waste_incinerator"), cid); // @todo: class mapping
player_ = player_inventory.player;
inventory_ = block_inventory;
wpc_ = wpc;

View file

@ -20,6 +20,7 @@ import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.VineBlock;
import net.minecraft.world.level.block.state.BlockState;
import wile.engineersdecor.ModEngineersDecor;
import wile.engineersdecor.libmc.detail.Auxiliaries;
import java.util.*;
@ -40,7 +41,7 @@ public class TreeCutting
);
private static boolean isLog(BlockState state)
{ return (state.is(BlockTags.LOGS)) || (state.getBlock().getTags().contains(new ResourceLocation("minecraft","logs"))); }
{ return (state.is(BlockTags.LOGS)); }
private static boolean isSameLog(BlockState a, BlockState b)
{ return (a.getBlock()==b.getBlock()); }
@ -48,7 +49,7 @@ public class TreeCutting
private static boolean isLeaves(BlockState state)
{
if(state.getBlock() instanceof LeavesBlock) return true;
if(state.getBlock().getTags().contains(new ResourceLocation("minecraft","leaves"))) return true;
if(state.is(BlockTags.LEAVES)) return true;
return false;
}

View file

@ -10,13 +10,13 @@ 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;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import mezz.jei.api.registration.IRecipeCatalystRegistration;
import mezz.jei.api.constants.VanillaRecipeCategoryUid;
import mezz.jei.api.registration.IRecipeTransferRegistration;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.runtime.IJeiRuntime;
@ -42,11 +42,11 @@ public class JEIPlugin implements mezz.jei.api.IModPlugin
@Override
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration)
{
if(!ModConfig.isOptedOut(ModContent.CRAFTING_TABLE)) {
if(!ModConfig.isOptedOut(ModContent.getBlock("metal_crafting_table"))) {
try {
registration.addRecipeTransferHandler(
EdCraftingTable.CraftingTableUiContainer.class,
VanillaRecipeCategoryUid.CRAFTING,
RecipeTypes.CRAFTING,
1, 9, 10, 36+CraftingTableTileEntity.NUM_OF_STORAGE_SLOTS
);
} catch(Throwable e) {
@ -82,14 +82,14 @@ public class JEIPlugin implements mezz.jei.api.IModPlugin
@Override
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration)
{
if(!ModConfig.isOptedOut(ModContent.CRAFTING_TABLE)) {
registration.addRecipeCatalyst(new ItemStack(ModContent.CRAFTING_TABLE), VanillaRecipeCategoryUid.CRAFTING);
if(!ModConfig.isOptedOut(ModContent.getBlock("metal_crafting_table"))) {
registration.addRecipeCatalyst(new ItemStack(ModContent.getBlock("metal_crafting_table")), RecipeTypes.CRAFTING);
}
if(!ModConfig.isOptedOut(ModContent.SMALL_LAB_FURNACE)) {
registration.addRecipeCatalyst(new ItemStack(ModContent.SMALL_LAB_FURNACE), VanillaRecipeCategoryUid.FURNACE);
if(!ModConfig.isOptedOut(ModContent.getBlock("small_lab_furnace"))) {
registration.addRecipeCatalyst(new ItemStack(ModContent.getBlock("small_lab_furnace")), RecipeTypes.SMELTING);
}
if(!ModConfig.isOptedOut(ModContent.SMALL_ELECTRICAL_FURNACE)) {
registration.addRecipeCatalyst(new ItemStack(ModContent.SMALL_ELECTRICAL_FURNACE), VanillaRecipeCategoryUid.FURNACE);
if(!ModConfig.isOptedOut(ModContent.getBlock("small_electrical_furnace"))) {
registration.addRecipeCatalyst(new ItemStack(ModContent.getBlock("small_electrical_furnace")), RecipeTypes.SMELTING);
}
}
}

View file

@ -16,9 +16,9 @@ import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import wile.engineersdecor.ModEngineersDecor;
import wile.engineersdecor.ModConfig;
import wile.engineersdecor.libmc.detail.Auxiliaries;
import wile.engineersdecor.libmc.detail.Registries;
import javax.annotation.Nullable;
import java.util.ArrayList;
@ -28,11 +28,8 @@ import java.util.List;
public class EdItem extends Item
{
public static final Collection<CreativeModeTab> ENABLED_TABS = Collections.singletonList(ModEngineersDecor.ITEMGROUP);
public static final Collection<CreativeModeTab> DISABLED_TABS = new ArrayList<CreativeModeTab>();
public EdItem(Item.Properties properties)
{ super(properties.tab(ModEngineersDecor.ITEMGROUP)); }
{ super(properties.tab(Registries.getCreativeModeTab())); }
@Override
@OnlyIn(Dist.CLIENT)
@ -41,6 +38,5 @@ public class EdItem extends Item
@Override
public Collection<CreativeModeTab> getCreativeTabs()
{ return ModConfig.isOptedOut(this) ? (DISABLED_TABS) : (ENABLED_TABS); }
{ return ModConfig.isOptedOut(this) ? (new ArrayList<>()) : (Collections.singletonList(Registries.getCreativeModeTab())); }
}

View file

@ -27,7 +27,10 @@ import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;

View file

@ -9,6 +9,7 @@
package wile.engineersdecor.libmc.blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
@ -20,6 +21,7 @@ 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;
@ -28,8 +30,8 @@ public class StandardEntityBlocks
{
public interface IStandardEntityBlock<ET extends StandardBlockEntity> extends EntityBlock
{
@Nullable
BlockEntityType<ET> getBlockEntityType();
ResourceLocation getBlockRegistryName();
default boolean isBlockEntityTicking(Level world, BlockState state)
{ return false; }
@ -46,7 +48,10 @@ public class StandardEntityBlocks
@Override
@Nullable
default BlockEntity newBlockEntity(BlockPos pos, BlockState state)
{ return (getBlockEntityType()==null) ? null : getBlockEntityType().create(pos, state); }
{
BlockEntityType<?> tet = Registries.getBlockEntityTypeOfBlock(getBlockRegistryName().getPath());
return (tet==null) ? null : tet.create(pos, state);
}
@Override
@Nullable

View file

@ -31,9 +31,6 @@ public class StandardStairsBlock extends StairBlock implements StandardBlocks.IS
{
private final long config;
public StandardStairsBlock(long config, BlockState state, BlockBehaviour.Properties properties)
{ super(()->state, properties); this.config = config; }
public StandardStairsBlock(long config, java.util.function.Supplier<BlockState> state, BlockBehaviour.Properties properties)
{ super(state, properties); this.config = config; }

View file

@ -83,7 +83,7 @@ public class VariantSlabBlock extends StandardBlocks.WaterLoggable implements St
public void appendHoverText(ItemStack stack, @Nullable BlockGetter world, List<Component> tooltip, TooltipFlag flag)
{
if(!Auxiliaries.Tooltip.addInformation(stack, world, tooltip, flag, true)) return;
if(with_pickup) Auxiliaries.Tooltip.addInformation("engineersdecor.tooltip.slabpickup", "engineersdecor.tooltip.slabpickup", tooltip, flag, true);
if(with_pickup && Auxiliaries.Tooltip.helpCondition()) Auxiliaries.Tooltip.addInformation("engineersdecor.tooltip.slabpickup", "engineersdecor.tooltip.slabpickup", tooltip, flag, true);
}
@Override

View file

@ -17,22 +17,25 @@ 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.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.fml.ModList;
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.lwjgl.glfw.GLFW;
import wile.engineersdecor.ModConfig;
import javax.annotation.Nullable;
import java.io.BufferedReader;
@ -113,9 +116,6 @@ public class Auxiliaries
public static void logError(final String msg)
{ logger.error(msg); }
public static void logDebug(final String msg)
{ if(ModConfig.withDebugLogging()) logger.info(msg); }
// -------------------------------------------------------------------------------------------------------------------
// Localization, text formatting
// -------------------------------------------------------------------------------------------------------------------
@ -254,6 +254,20 @@ public class Auxiliaries
public static String serializeTextComponent(Component tc)
{ return (tc==null) ? ("") : (Component.Serializer.toJson(tc)); }
// -------------------------------------------------------------------------------------------------------------------
// Tag Handling
// -------------------------------------------------------------------------------------------------------------------
@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));
}
@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)); }
// -------------------------------------------------------------------------------------------------------------------
// Item NBT data
// -------------------------------------------------------------------------------------------------------------------
@ -379,7 +393,7 @@ public class Auxiliaries
return shape;
}
public static final AABB[] getMappedAABB(AABB[] bbs, Function<AABB,AABB> mapper) {
public static AABB[] getMappedAABB(AABB[] bbs, Function<AABB,AABB> mapper) {
final AABB[] transformed = new AABB[bbs.length];
for(int i=0; i<bbs.length; ++i) transformed[i] = mapper.apply(bbs[i]);
return transformed;

View file

@ -12,6 +12,7 @@ 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;
@ -942,12 +943,21 @@ public class Inventories
public static NonNullList<ItemStack> readNbtStacks(CompoundTag nbt, String key, int size)
{
NonNullList<ItemStack> stacks = NonNullList.withSize(size, ItemStack.EMPTY);
if((nbt == null) || (!nbt.contains(key,10))) return stacks;
if((nbt == null) || (!nbt.contains(key, Tag.TAG_COMPOUND))) return stacks;
CompoundTag stacknbt = nbt.getCompound(key);
ContainerHelper.loadAllItems(stacknbt, stacks);
return stacks;
}
public static NonNullList<ItemStack> readNbtStacks(CompoundTag nbt, int size)
{
NonNullList<ItemStack> stacks = NonNullList.withSize(size, ItemStack.EMPTY);
if((nbt == null) || (!nbt.contains("Items", Tag.TAG_LIST))) return stacks;
ContainerHelper.loadAllItems(nbt, stacks);
return stacks;
}
public static CompoundTag writeNbtStacks(CompoundTag nbt, String key, NonNullList<ItemStack> stacks, boolean omit_trailing_empty)
{
CompoundTag stacknbt = new CompoundTag();

View file

@ -8,23 +8,21 @@
*/
package wile.engineersdecor.libmc.detail;
import net.minecraft.core.Registry;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.*;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.crafting.conditions.ICondition;
import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
import net.minecraftforge.registries.ForgeRegistries;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraftforge.registries.IForgeRegistry;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
@ -97,11 +95,11 @@ public class OptionalRecipeCondition implements ICondition
if(without_recipes) return false;
if((experimental) && (!with_experimental)) return false;
final IForgeRegistry<Item> item_registry = ForgeRegistries.ITEMS;
final Collection<ResourceLocation> item_tags = SerializationTags.getInstance().getOrEmpty(Registry.ITEM_REGISTRY).getAvailableTags();
//final Collection<ResourceLocation> item_tags = SerializationTags.getInstance().getOrEmpty(Registry.ITEM_REGISTRY).getAvailableTags();
if(result != null) {
boolean item_registered = item_registry.containsKey(result);
if(!item_registered) return false; // required result not registered
if(item_registered && item_optouts.test(item_registry.getValue(result))) return false;
if(item_optouts.test(item_registry.getValue(result))) return false;
if(ForgeRegistries.BLOCKS.containsKey(result) && block_optouts.test(ForgeRegistries.BLOCKS.getValue(result))) return false;
}
if(!all_required.isEmpty()) {
@ -111,7 +109,7 @@ public class OptionalRecipeCondition implements ICondition
}
if(!all_required_tags.isEmpty()) {
for(ResourceLocation rl:all_required_tags) {
if(!item_tags.contains(rl)) return false;
if(item_registry.tags().getTagNames().noneMatch(tk->tk.location().equals(rl))) return false; // if(!item_tags.contains(rl)) return false;
}
}
if(!any_missing.isEmpty()) {
@ -122,7 +120,7 @@ public class OptionalRecipeCondition implements ICondition
}
if(!any_missing_tags.isEmpty()) {
for(ResourceLocation rl:any_missing_tags) {
if(!item_tags.contains(rl)) return true;
if(item_registry.tags().getTagNames().noneMatch(tk->tk.location().equals(rl))) return true; // if(!item_tags.contains(rl)) return true;
}
return false;
}

View file

@ -0,0 +1,265 @@
/*
* @file Registries.java
* @author Stefan Wilhelm (wile)
* @copyright (C) 2020 Stefan Wilhelm
* @license MIT (see https://opensource.org/licenses/MIT)
*
* Common game registry handling.
*/
package wile.engineersdecor.libmc.detail;
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.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.registries.ForgeRegistries;
import wile.engineersdecor.libmc.blocks.StandardBlocks;
import javax.annotation.Nonnull;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
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; }
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)); }
});
}
return creative_tab;
}
// -------------------------------------------------------------------------------------------------------------
public static Block getBlock(String block_name)
{ return registered_blocks.get(block_name); }
public static Item getItem(String name)
{ return registered_items.get(name); }
public static EntityType<?> getEntityType(String name)
{ return registered_entity_types.get(name); }
public static BlockEntityType<?> getBlockEntityType(String block_name)
{ return registered_block_entity_types.get(block_name); }
public static MenuType<?> getMenuType(String name)
{ return registered_menu_types.get(name); }
public static BlockEntityType<?> getBlockEntityTypeOfBlock(String block_name)
{ return getBlockEntityType("tet_"+block_name); }
public static MenuType<?> getMenuTypeOfBlock(String name)
{ return getMenuType("ct_"+name); }
public static TagKey<Block> getBlockTagKey(String name)
{ return registered_block_tag_keys.get(name); }
public static TagKey<Item> getItemTagKey(String name)
{ return registered_item_tag_keys.get(name); }
// -------------------------------------------------------------------------------------------------------------
@Nonnull
public static List<Block> getRegisteredBlocks()
{ return Collections.unmodifiableList(registered_blocks.values().stream().toList()); }
@Nonnull
public static List<Item> getRegisteredItems()
{ return Collections.unmodifiableList(registered_items.values().stream().toList()); }
@Nonnull
public static List<BlockEntityType<?>> getRegisteredBlockEntityTypes()
{ return Collections.unmodifiableList(registered_block_entity_types.values().stream().toList()); }
@Nonnull
public static List<EntityType<?>> getRegisteredEntityTypes()
{ return Collections.unmodifiableList(registered_entity_types.values().stream().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;
}));
}
@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;
}));
}
@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, ()->{
final Block[] blocks = Arrays.stream(block_names).map(s->{
Block b = registered_blocks.get(s);
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;
}));
}
@SuppressWarnings("unchecked")
public static <T extends EntityType<?>> void addEntityType(String registry_name, Supplier<EntityType<?>> supplier)
{ entity_type_suppliers.add(new Tuple<>(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;
}));
}
@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 addOptionalBlockTag(String tag_name, ResourceLocation... default_blocks)
{
final Set<Supplier<Block>> default_suppliers = new HashSet<>();
for(ResourceLocation rl: default_blocks) default_suppliers.add(()->ForgeRegistries.BLOCKS.getValue(rl));
final TagKey<Block> key = ForgeRegistries.BLOCKS.tags().createOptionalTagKey(new ResourceLocation(modid, tag_name), default_suppliers);
registered_block_tag_keys.put(tag_name, key);
}
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));
final TagKey<Item> key = ForgeRegistries.ITEMS.tags().createOptionalTagKey(new ResourceLocation(modid, tag_name), default_suppliers);
registered_item_tag_keys.put(tag_name, key);
}
// -------------------------------------------------------------------------------------------------------------
public static void onBlockRegistry(BiConsumer<ResourceLocation, Block> registration)
{
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();
}
public static void onItemRegistry(BiConsumer<ResourceLocation, Item> registration)
{
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();
}
public static void onBlockEntityRegistry(BiConsumer<ResourceLocation, BlockEntityType<?>> registration)
{
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();
}
public static void onMenuTypeRegistry(BiConsumer<ResourceLocation, MenuType<?>> registration)
{
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();
}
public static void onEntityRegistry(BiConsumer<ResourceLocation, EntityType<?>> registration)
{
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();
}
}

View file

@ -19,13 +19,13 @@ logoFile="logo.png"
[[dependencies.engineersdecor]]
modId="forge"
mandatory=true
versionRange="[39,)"
versionRange="[40,)"
ordering="NONE"
side="BOTH"
[[dependencies.engineersdecor]]
modId="minecraft"
mandatory=true
versionRange="[1.18.1,1.19)"
versionRange="[1.18.2,1.19)"
ordering="NONE"
side="BOTH"