Fixed remaining compiler errors. Using deferred registries now, and cleaned up mods.toml file.

This commit is contained in:
Christian Knaapen
2021-09-12 13:54:25 +02:00
parent 178a4ca4e1
commit d9df8b0d0e
20 changed files with 178 additions and 378 deletions

View File

@@ -87,7 +87,8 @@ public class BuildConfig {
"0: blocks that can be harvested with wooden or gold tools",
"1: blocks that can be harvested with stone tools",
"2: blocks that can be harvested with iron tools",
"3: blocks that can be harvested with diamond tools")
"3: blocks that can be harvested with diamond tools",
"4: blocks that can be harvested with netherite tools")
.defineInRange("quickReplaceMiningLevel", -1, -1, 3);
undoStackSize = builder
@@ -102,7 +103,7 @@ public class BuildConfig {
public static class Visuals {
public final ForgeConfigSpec.ConfigValue<Boolean> alwaysShowBlockPreview;
public final ForgeConfigSpec.ConfigValue<Double> dissolveTimeMultiplier;
public final ForgeConfigSpec.ConfigValue<Integer> shaderTreshold;
public final ForgeConfigSpec.ConfigValue<Integer> shaderThreshold;
public final ForgeConfigSpec.ConfigValue<Boolean> useShaders;
public Visuals(ForgeConfigSpec.Builder builder) {
@@ -120,7 +121,7 @@ public class BuildConfig {
"Relaxing: 1.5")
.define("dissolveTimeMultiplier", 1.0);
shaderTreshold = builder
shaderThreshold = builder
.comment("Switch to using the simple performance shader when placing more than this many blocks.")
.define("shaderTreshold", 1500);

View File

@@ -1,6 +1,5 @@
package nl.requios.effortlessbuilding;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
@@ -8,7 +7,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.chat.TextComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModLoadingContext;
@@ -16,8 +15,6 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fmllegacy.RegistryObject;
import net.minecraftforge.fmllegacy.network.IContainerFactory;
@@ -29,10 +26,10 @@ import nl.requios.effortlessbuilding.capability.ModifierCapabilityManager;
import nl.requios.effortlessbuilding.command.CommandReach;
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
import nl.requios.effortlessbuilding.gui.RandomizerBagContainer;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.item.ItemReachUpgrade1;
import nl.requios.effortlessbuilding.item.ItemReachUpgrade2;
import nl.requios.effortlessbuilding.item.ItemReachUpgrade3;
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
import nl.requios.effortlessbuilding.item.ReachUpgrade1Item;
import nl.requios.effortlessbuilding.item.ReachUpgrade2Item;
import nl.requios.effortlessbuilding.item.ReachUpgrade3Item;
import nl.requios.effortlessbuilding.network.PacketHandler;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
import nl.requios.effortlessbuilding.proxy.IProxy;
@@ -42,47 +39,38 @@ import org.apache.logging.log4j.Logger;
// The value here should match an entry in the META-INF/mods.toml file
@Mod(EffortlessBuilding.MODID)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class EffortlessBuilding {
public static final String MODID = "effortlessbuilding";
public static final Logger logger = LogManager.getLogger();
public static final ItemRandomizerBag ITEM_RANDOMIZER_BAG = new ItemRandomizerBag();
public static final ItemReachUpgrade1 ITEM_REACH_UPGRADE_1 = new ItemReachUpgrade1();
public static final ItemReachUpgrade2 ITEM_REACH_UPGRADE_2 = new ItemReachUpgrade2();
public static final ItemReachUpgrade3 ITEM_REACH_UPGRADE_3 = new ItemReachUpgrade3();
public static final Block[] BLOCKS = {
};
public static final Item[] ITEMS = {
ITEM_RANDOMIZER_BAG,
ITEM_REACH_UPGRADE_1,
ITEM_REACH_UPGRADE_2,
ITEM_REACH_UPGRADE_3
};
public static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, EffortlessBuilding.MODID);
public static final RegistryObject<MenuType<RandomizerBagContainer>> RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("randomizer_bag", () -> registerContainer(RandomizerBagContainer::new));
public static final ResourceLocation RANDOMIZER_BAG_GUI = new ResourceLocation(EffortlessBuilding.MODID, "randomizer_bag");
public static EffortlessBuilding instance;
public static IProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> ServerProxy::new);
//Registration
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
private static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, EffortlessBuilding.MODID);
public static final RegistryObject<Item> RANDOMIZER_BAG_ITEM = ITEMS.register("randomizer_bag", RandomizerBagItem::new);
public static final RegistryObject<Item> REACH_UPGRADE_1_ITEM = ITEMS.register("reach_upgrade_1", ReachUpgrade1Item::new);
public static final RegistryObject<Item> REACH_UPGRADE_2_ITEM = ITEMS.register("reach_upgrade_2", ReachUpgrade2Item::new);
public static final RegistryObject<Item> REACH_UPGRADE_3_ITEM = ITEMS.register("reach_upgrade_3", ReachUpgrade3Item::new);
public static final RegistryObject<MenuType<RandomizerBagContainer>> RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("randomizer_bag", () -> registerContainer(RandomizerBagContainer::new));
public static final ResourceLocation RANDOMIZER_BAG_GUI = new ResourceLocation(EffortlessBuilding.MODID, "randomizer_bag");
public EffortlessBuilding() {
instance = this;
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// Register the enqueueIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
// Register the processIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
// Register the clientSetup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
//Register config
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, BuildConfig.spec);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
CONTAINERS.register(FMLJavaModLoadingContext.get().getModEventBus());
//Register config
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, BuildConfig.spec);
}
public static <T extends AbstractContainerMenu> MenuType<T> registerContainer(IContainerFactory<T> fact){
@@ -90,6 +78,32 @@ public class EffortlessBuilding {
return type;
}
@SubscribeEvent
public void setup(final FMLCommonSetupEvent event) {
PacketHandler.register();
proxy.setup(event);
CompatHelper.setup();
}
@SubscribeEvent
public void clientSetup(final FMLClientSetupEvent event) {
proxy.clientSetup(event);
}
@SubscribeEvent
public void registerCapabilities(RegisterCapabilitiesEvent event){
event.register(ModifierCapabilityManager.IModifierCapability.class);
event.register(ModeCapabilityManager.IModeCapability.class);
}
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
CommandReach.register(event.getServer().getCommands().getDispatcher());
}
public static void log(String msg) {
logger.info(msg);
}
@@ -106,43 +120,4 @@ public class EffortlessBuilding {
public static void logTranslate(Player player, String prefix, String translationKey, String suffix, boolean actionBar) {
proxy.logTranslate(player, prefix, translationKey, suffix, actionBar);
}
@SubscribeEvent
public void setup(final FMLCommonSetupEvent event) {
PacketHandler.register();
//TODO 1.13 config
// ConfigManager.sync(MODID, Config.Type.INSTANCE);
proxy.setup(event);
CompatHelper.setup();
}
@SubscribeEvent
public void clientSetup(final FMLClientSetupEvent event) {
proxy.clientSetup(event);
}
@SubscribeEvent
public void enqueueIMC(final InterModEnqueueEvent event) {
// some example code to dispatch IMC to another mod
// InterModComms.sendTo("examplemod", "helloworld", () -> { logger.info("Hello world from the MDK"); return "Hello world";});
}
@SubscribeEvent
public void processIMC(final InterModProcessEvent event) {
// some example code to receive and process InterModComms from other mods
// logger.info("Got IMC {}", event.getIMCStream().
// map(m->m.getMessageSupplier().get()).
// collect(Collectors.toList()));
}
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
CommandReach.register(event.getServer().getCommands().getDispatcher());
}
}

View File

@@ -43,21 +43,6 @@ public class EventHandler {
}
}
//TODO 1.13 config
// @SubscribeEvent
// public static void onConfigChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
// {
// if (event.getModID().equals(EffortlessBuilding.MODID))
// {
// ConfigManager.sync(EffortlessBuilding.MODID, Config.Type.INSTANCE);
// }
// }
// @SubscribeEvent
// public static void onServerTick(TickEvent.ServerTickEvent event) {
//
// }
@SubscribeEvent
//Only called serverside (except with lilypads...)
public static void onBlockPlaced(BlockEvent.EntityPlaceEvent event) {

View File

@@ -1,45 +0,0 @@
package nl.requios.effortlessbuilding;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import nl.requios.effortlessbuilding.capability.ModeCapabilityManager;
import nl.requios.effortlessbuilding.capability.ModifierCapabilityManager;
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModEventHandler {
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event) {
event.getRegistry().registerAll(EffortlessBuilding.BLOCKS);
}
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
event.getRegistry().registerAll(EffortlessBuilding.ITEMS);
for (Block block : EffortlessBuilding.BLOCKS) {
event.getRegistry().register(new BlockItem(block, new Item.Properties()).setRegistryName(block.getRegistryName()));
}
}
@SubscribeEvent
public static void registerCapabilities(RegisterCapabilitiesEvent event){
event.register(ModifierCapabilityManager.IModifierCapability.class);
event.register(ModeCapabilityManager.IModeCapability.class);
}
// @SubscribeEvent
// public static void registerContainerTypes(RegistryEvent.Register<ContainerType<?>> event) {
// event.getRegistry().register()
// }
}

View File

@@ -9,7 +9,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
import net.minecraft.core.Vec3i;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
import java.util.ArrayList;
import java.util.List;
@@ -46,8 +46,8 @@ public class Array {
//Randomizer bag synergy
IItemHandler bagInventory = null;
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemRandomizerBag) {
bagInventory = ItemRandomizerBag.getBagInventory(itemStack);
if (!itemStack.isEmpty() && itemStack.getItem() instanceof RandomizerBagItem) {
bagInventory = RandomizerBagItem.getBagInventory(itemStack);
}
for (int i = 0; i < a.count; i++) {
@@ -55,7 +55,7 @@ public class Array {
//Randomizer bag synergy
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
itemStack = RandomizerBagItem.pickRandomStack(bagInventory);
blockState = BuildModifiers
.getBlockStateFromItem(itemStack, player, startPos, Direction.UP, new Vec3(0, 0, 0), InteractionHand.MAIN_HAND);
}

View File

@@ -17,11 +17,10 @@ import net.minecraft.world.level.Level;
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
import nl.requios.effortlessbuilding.helper.InventoryHelper;
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
import nl.requios.effortlessbuilding.render.BlockPreviewRenderer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -30,7 +29,7 @@ public class BuildModifiers {
//Called from BuildModes
public static void onBlockPlaced(Player player, List<BlockPos> startCoordinates, Direction sideHit, Vec3 hitVec, boolean placeStartPos) {
Level world = player.level;
ItemRandomizerBag.renewRandomness();
RandomizerBagItem.renewRandomness();
//Format hitvec to 0.x
hitVec = new Vec3(Math.abs(hitVec.x - ((int) hitVec.x)), Math.abs(hitVec.y - ((int) hitVec.y)), Math.abs(hitVec.z - ((int) hitVec.z)));
@@ -193,7 +192,7 @@ public class BuildModifiers {
ItemStack itemBlock = ItemStack.EMPTY;
if (itemStack.getItem() instanceof BlockItem) itemBlock = itemStack;
else itemBlock = CompatHelper.getItemBlockFromStack(itemStack);
ItemRandomizerBag.resetRandomness();
RandomizerBagItem.resetRandomness();
//Add blocks in posList first
for (BlockPos blockPos : posList) {

View File

@@ -9,7 +9,7 @@ import net.minecraft.world.InteractionHand;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
import java.util.ArrayList;
import java.util.List;
@@ -71,8 +71,8 @@ public class Mirror {
//Randomizer bag synergy
IItemHandler bagInventory = null;
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemRandomizerBag) {
bagInventory = ItemRandomizerBag.getBagInventory(itemStack);
if (!itemStack.isEmpty() && itemStack.getItem() instanceof RandomizerBagItem) {
bagInventory = RandomizerBagItem.getBagInventory(itemStack);
}
if (m.mirrorX)
@@ -93,7 +93,7 @@ public class Mirror {
//Randomizer bag synergy
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
itemStack = RandomizerBagItem.pickRandomStack(bagInventory);
oldBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, oldBlockPos, Direction.UP, new Vec3(0, 0, 0), hand);
}
@@ -118,7 +118,7 @@ public class Mirror {
//Randomizer bag synergy
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
itemStack = RandomizerBagItem.pickRandomStack(bagInventory);
oldBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, oldBlockPos, Direction.UP, new Vec3(0, 0, 0), hand);
}
@@ -141,7 +141,7 @@ public class Mirror {
//Randomizer bag synergy
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
itemStack = RandomizerBagItem.pickRandomStack(bagInventory);
oldBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, oldBlockPos, Direction.UP, new Vec3(0, 0, 0), hand);
}

View File

@@ -11,7 +11,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
import java.util.ArrayList;
import java.util.List;
@@ -75,8 +75,8 @@ public class RadialMirror {
//Randomizer bag synergy
IItemHandler bagInventory = null;
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemRandomizerBag) {
bagInventory = ItemRandomizerBag.getBagInventory(itemStack);
if (!itemStack.isEmpty() && itemStack.getItem() instanceof RandomizerBagItem) {
bagInventory = RandomizerBagItem.getBagInventory(itemStack);
}
BlockState newBlockState;
@@ -96,7 +96,7 @@ public class RadialMirror {
//Randomizer bag synergy
if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
itemStack = RandomizerBagItem.pickRandomStack(bagInventory);
newBlockState = BuildModifiers
.getBlockStateFromItem(itemStack, player, startPos, Direction.UP, new Vec3(0, 0, 0), InteractionHand.MAIN_HAND);

View File

@@ -8,13 +8,13 @@ import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ItemHandlerCapabilityProvider implements ICapabilitySerializable<CompoundTag> {
IItemHandler itemHandler = new ItemStackHandler(ItemRandomizerBag.INV_SIZE);
IItemHandler itemHandler = new ItemStackHandler(RandomizerBagItem.INV_SIZE);
@Nonnull
@Override

View File

@@ -9,7 +9,7 @@ import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
public class CompatHelper {
//TODO 1.13 compatibility
@@ -40,7 +40,7 @@ public class CompatHelper {
Item item = stack.getItem();
if (item instanceof BlockItem)
return true;
return item instanceof ItemRandomizerBag;
return item instanceof RandomizerBagItem;
//TODO 1.13 compatibility
// if (item == dankNullItem)
// return true;
@@ -55,11 +55,11 @@ public class CompatHelper {
return proxy;
//Randomizer Bag
if (proxyItem instanceof ItemRandomizerBag) {
if (proxyItem instanceof RandomizerBagItem) {
ItemStack itemStack = proxy;
while (!(itemStack.getItem() instanceof BlockItem || itemStack.isEmpty())) {
if (itemStack.getItem() instanceof ItemRandomizerBag)
itemStack = ItemRandomizerBag.pickRandomStack(ItemRandomizerBag.getBagInventory(itemStack));
if (itemStack.getItem() instanceof RandomizerBagItem)
itemStack = RandomizerBagItem.pickRandomStack(RandomizerBagItem.getBagInventory(itemStack));
}
return itemStack;
}
@@ -82,9 +82,9 @@ public class CompatHelper {
Item blockItem = Item.byBlock(state.getBlock());
if (stack.getItem() instanceof BlockItem)
return stack;
else if (stack.getItem() instanceof ItemRandomizerBag) {
IItemHandler bagInventory = ItemRandomizerBag.getBagInventory(stack);
return ItemRandomizerBag.findStack(bagInventory, blockItem);
else if (stack.getItem() instanceof RandomizerBagItem) {
IItemHandler bagInventory = RandomizerBagItem.getBagInventory(stack);
return RandomizerBagItem.findStack(bagInventory, blockItem);
}
//TODO 1.13 compatibility
// else if (stack.getItem() == dankNullItem) {

View File

@@ -13,11 +13,11 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.items.SlotItemHandler;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
public class RandomizerBagContainer extends AbstractContainerMenu {
private static final int INV_START = ItemRandomizerBag.INV_SIZE, INV_END = INV_START + 26,
private static final int INV_START = RandomizerBagItem.INV_SIZE, INV_END = INV_START + 26,
HOTBAR_START = INV_END + 1, HOTBAR_END = HOTBAR_START + 8;
private final IItemHandler bagInventory;
@@ -33,14 +33,14 @@ public class RandomizerBagContainer extends AbstractContainerMenu {
//Server?
public RandomizerBagContainer(int containerId, Inventory playerInventory) {
this(containerId, playerInventory, new ItemStackHandler(ItemRandomizerBag.INV_SIZE));
this(containerId, playerInventory, new ItemStackHandler(RandomizerBagItem.INV_SIZE));
}
public RandomizerBagContainer(int containerId, Inventory playerInventory, IItemHandler inventory) {
super(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER.get(), containerId);
bagInventory = inventory;
for (int i = 0; i < ItemRandomizerBag.INV_SIZE; ++i) {
for (int i = 0; i < RandomizerBagItem.INV_SIZE; ++i) {
this.addSlot(new SlotItemHandler(bagInventory, i, 44 + (18 * i), 20));
}

View File

@@ -24,7 +24,6 @@ import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import static nl.requios.effortlessbuilding.buildmode.BuildModes.BuildModeEnum;
import static nl.requios.effortlessbuilding.buildmode.ModeOptions.*;
import nl.requios.effortlessbuilding.buildmode.BuildModes.BuildModeEnum;
@@ -87,8 +86,8 @@ public class RadialMenu extends Screen {
BuildModeEnum currentBuildMode = ModeSettingsManager.getModeSettings(Minecraft.getInstance().player).getBuildMode();
RenderSystem.pushMatrix();
RenderSystem.translatef(0.0F, 0.0F, 200.0F);
ms.pushPose();
ms.translate(0, 0, 200);
final int startColor = (int) (visibility * 98) << 24;
final int endColor = (int) (visibility * 128) << 24;
@@ -97,13 +96,15 @@ public class RadialMenu extends Screen {
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.disableAlphaTest();
//TODO 1.17
// RenderSystem.disableAlphaTest();
RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
RenderSystem.shadeModel(GL11.GL_SMOOTH);
//TODO 1.17
// RenderSystem.shadeModel(GL11.GL_SMOOTH);
final Tesselator tessellator = Tesselator.getInstance();
final BufferBuilder buffer = tessellator.getBuilder();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormat.POSITION_COLOR);
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
final double middleX = width / 2.0;
final double middleY = height / 2.0;
@@ -258,13 +259,15 @@ public class RadialMenu extends Screen {
tessellator.end();
RenderSystem.shadeModel(GL11.GL_FLAT);
//TODO 1.17
// RenderSystem.shadeModel(GL11.GL_FLAT);
RenderSystem.translatef(0f, 0f, 5f);
ms.translate(0f, 0f, 5f);
RenderSystem.enableTexture();
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
RenderSystem.disableBlend();
RenderSystem.enableAlphaTest();
//TODO 1.17
// RenderSystem.enableAlphaTest();
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
@@ -420,7 +423,7 @@ public class RadialMenu extends Screen {
}
}
RenderSystem.popMatrix();
ms.popPose();
}
private boolean inTriangle(final double x1, final double y1, final double x2, final double y2,

View File

@@ -1,6 +1,9 @@
package nl.requios.effortlessbuilding.helper;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.Tag;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
@@ -15,7 +18,8 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.common.data.ForgeBlockTagsProvider;
import net.minecraftforge.event.ForgeEventFactory;
import nl.requios.effortlessbuilding.BuildConfig;
import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager;
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
@@ -31,6 +35,8 @@ import net.minecraft.world.level.block.state.BlockState;
public class SurvivalHelper {
private static final Tag.Named<Block> NEEDS_NETHERITE_TOOL = BlockTags.bind("forge:needs_netherite_tool");
//Used for all placing of blocks in this mod.
//Checks if area is loaded, if player has the right permissions, if existing block can be replaced (drops it if so) and consumes an item from the stack.
//Based on ItemBlock#onItemUse
@@ -208,17 +214,26 @@ public class SurvivalHelper {
BlockState state = world.getBlockState(pos);
switch (BuildConfig.survivalBalancers.quickReplaceMiningLevel.get()) {
int miningLevel = BuildConfig.survivalBalancers.quickReplaceMiningLevel.get();
switch (miningLevel) {
case -1:
return !state.requiresCorrectToolForDrops();
case 0:
return state.getBlock().getHarvestLevel(state) <= 0;
return !state.is(BlockTags.NEEDS_STONE_TOOL) &&
!state.is(BlockTags.NEEDS_IRON_TOOL) &&
!state.is(BlockTags.NEEDS_DIAMOND_TOOL) &&
!state.is(NEEDS_NETHERITE_TOOL);
case 1:
return state.getBlock().getHarvestLevel(state) <= 1;
return !state.is(BlockTags.NEEDS_IRON_TOOL) &&
!state.is(BlockTags.NEEDS_DIAMOND_TOOL) &&
!state.is(NEEDS_NETHERITE_TOOL);
case 2:
return state.getBlock().getHarvestLevel(state) <= 2;
return !state.is(BlockTags.NEEDS_DIAMOND_TOOL) &&
!state.is(NEEDS_NETHERITE_TOOL);
case 3:
return state.getBlock().getHarvestLevel(state) <= 3;
return !state.is(NEEDS_NETHERITE_TOOL);
case 4:
return true;
}
return false;
@@ -281,36 +296,7 @@ public class SurvivalHelper {
if (player.isCreative()) return true;
return canHarvestBlock(blockState.getBlock(), player, world, pos);
}
//From ForgeHooks#canHarvestBlock
public static boolean canHarvestBlock(@Nonnull Block block, @Nonnull Player player, @Nonnull Level world, @Nonnull BlockPos pos) {
BlockState state = world.getBlockState(pos);
//Dont break bedrock
if (state.getDestroySpeed(world, pos) < 0) {
return false;
}
if (!state.requiresCorrectToolForDrops()) {
return true;
}
ItemStack stack = player.getMainHandItem();
ToolType tool = block.getHarvestTool(state);
if (stack.isEmpty() || tool == null) {
return player.hasCorrectToolForDrops(state);
}
if (stack.getDamageValue() >= stack.getMaxDamage()) return false;
int toolLevel = stack.getItem().getHarvestLevel(stack, tool, player, state);
if (toolLevel < 0) {
return player.hasCorrectToolForDrops(state);
}
return toolLevel >= block.getHarvestLevel(state);
return ForgeEventFactory.doPlayerHarvestCheck(player, blockState, true);
}
public static boolean doesBecomeDoubleSlab(Player player, BlockPos pos, Direction facing) {

View File

@@ -50,16 +50,14 @@ import net.minecraft.world.item.context.UseOnContext;
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class ItemRandomizerBag extends Item {
public class RandomizerBagItem extends Item {
public static final int INV_SIZE = 5;
private static long currentSeed = 1337;
private static final Random rand = new Random(currentSeed);
public ItemRandomizerBag() {
public RandomizerBagItem() {
super(new Item.Properties().tab(CreativeModeTab.TAB_TOOLS).stacksTo(1));
this.setRegistryName(EffortlessBuilding.MODID, "randomizer_bag");
}
/**
@@ -250,7 +248,7 @@ public class ItemRandomizerBag extends Item {
@Nullable
@Override
public AbstractContainerMenu createMenu(int containerId, Inventory playerInventory, Player player) {
return new RandomizerBagContainer(containerId, playerInventory, ItemRandomizerBag.getBagInventory(bag));
return new RandomizerBagContainer(containerId, playerInventory, RandomizerBagItem.getBagInventory(bag));
}
}
}

View File

@@ -27,11 +27,10 @@ import net.minecraft.world.InteractionResultHolder;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ItemReachUpgrade1 extends Item {
public class ReachUpgrade1Item extends Item {
public ItemReachUpgrade1() {
public ReachUpgrade1Item() {
super(new Item.Properties().tab(CreativeModeTab.TAB_TOOLS).stacksTo(1));
this.setRegistryName(EffortlessBuilding.MODID, "reach_upgrade1");
}
@Override

View File

@@ -27,11 +27,10 @@ import net.minecraft.world.InteractionResultHolder;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ItemReachUpgrade2 extends Item {
public class ReachUpgrade2Item extends Item {
public ItemReachUpgrade2() {
public ReachUpgrade2Item() {
super(new Item.Properties().tab(CreativeModeTab.TAB_TOOLS).stacksTo(1));
this.setRegistryName(EffortlessBuilding.MODID, "reach_upgrade2");
}
@Override

View File

@@ -27,11 +27,10 @@ import net.minecraft.world.InteractionResultHolder;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ItemReachUpgrade3 extends Item {
public class ReachUpgrade3Item extends Item {
public ItemReachUpgrade3() {
public ReachUpgrade3Item() {
super(new Item.Properties().tab(CreativeModeTab.TAB_TOOLS).stacksTo(1));
this.setRegistryName(EffortlessBuilding.MODID, "reach_upgrade3");
}
@Override

View File

@@ -32,7 +32,7 @@ import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager.Modif
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
import nl.requios.effortlessbuilding.helper.ReachHelper;
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
import java.util.ArrayList;
@@ -168,7 +168,7 @@ public class BlockPreviewRenderer {
previousSecondPos = secondPos;
//if so, renew randomness of randomizer bag
ItemRandomizerBag.renewRandomness();
RandomizerBagItem.renewRandomness();
//and play sound (max once every tick)
if (newCoordinates.size() > 1 && blockStates.size() > 1 && soundTime < ClientProxy.ticksInGame - 0) {
soundTime = ClientProxy.ticksInGame;
@@ -187,7 +187,7 @@ public class BlockPreviewRenderer {
int blockCount;
//Use fancy shader if config allows, otherwise outlines
if (BuildConfig.visuals.useShaders.get() && newCoordinates.size() < BuildConfig.visuals.shaderTreshold.get()) {
if (BuildConfig.visuals.useShaders.get() && newCoordinates.size() < BuildConfig.visuals.shaderThreshold.get()) {
blockCount = renderBlockPreviews(matrixStack, renderTypeBuffer, newCoordinates, blockStates, itemStacks, 0f, firstPos, secondPos, !breaking, breaking);
} else {
VertexConsumer buffer = RenderHandler.beginLines(renderTypeBuffer);
@@ -314,7 +314,7 @@ public class BlockPreviewRenderer {
//Save current coordinates, blockstates and itemstacks
if (!coordinates.isEmpty() && blockStates.size() == coordinates.size() &&
coordinates.size() > 1 && coordinates.size() < BuildConfig.visuals.shaderTreshold.get()) {
coordinates.size() > 1 && coordinates.size() < BuildConfig.visuals.shaderThreshold.get()) {
placedDataList.add(new PlacedData(ClientProxy.ticksInGame, coordinates, blockStates,
itemStacks, firstPos, secondPos, false));
@@ -338,7 +338,7 @@ public class BlockPreviewRenderer {
//Save current coordinates, blockstates and itemstacks
if (!coordinates.isEmpty() && blockStates.size() == coordinates.size() &&
coordinates.size() > 1 && coordinates.size() < BuildConfig.visuals.shaderTreshold.get()) {
coordinates.size() > 1 && coordinates.size() < BuildConfig.visuals.shaderThreshold.get()) {
sortOnDistanceToPlayer(coordinates, player);

View File

@@ -9,30 +9,12 @@ import net.minecraft.client.renderer.texture.TextureAtlas;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
import org.lwjgl.opengl.*;
import java.util.OptionalDouble;
import java.util.function.Consumer;
public class BuildRenderTypes {
public static final RenderStateShard.TransparencyStateShard TRANSLUCENT_TRANSPARENCY;
public static final RenderStateShard.TransparencyStateShard NO_TRANSPARENCY;
//TODO 1.17
// public static final RenderStateShard.DiffuseLightingStateShard DIFFUSE_LIGHTING_ENABLED;
// public static final RenderStateShard.DiffuseLightingStateShard DIFFUSE_LIGHTING_DISABLED;
public static final RenderStateShard.LayeringStateShard PROJECTION_LAYERING;
public static final RenderStateShard.CullStateShard CULL_DISABLED;
//TODO 1.17
// public static final RenderStateShard.AlphaStateShard DEFAULT_ALPHA;
public static final RenderStateShard.WriteMaskStateShard WRITE_TO_DEPTH_AND_COLOR;
public static final RenderStateShard.WriteMaskStateShard COLOR_WRITE;
public class BuildRenderTypes extends RenderType {
public static final RenderType LINES;
public static final RenderType PLANES;
@@ -40,55 +22,35 @@ public class BuildRenderTypes {
private static final int secondaryTextureUnit = 2;
static {
TRANSLUCENT_TRANSPARENCY = ObfuscationReflectionHelper.getPrivateValue(RenderStateShard.class, null, "TRANSLUCENT_TRANSPARENCY");
NO_TRANSPARENCY = ObfuscationReflectionHelper.getPrivateValue(RenderStateShard.class, null, "NO_TRANSPARENCY");
PROJECTION_LAYERING = ObfuscationReflectionHelper.getPrivateValue(RenderStateShard.class, null, "VIEW_OFFSET_Z_LAYERING");
CULL_DISABLED = new RenderStateShard.CullStateShard(false);
//TODO 1.17
// DEFAULT_ALPHA = new RenderStateShard.AlphaStateShard(0.003921569F);
final boolean ENABLE_DEPTH_WRITING = true;
final boolean ENABLE_COLOUR_COMPONENTS_WRITING = true;
WRITE_TO_DEPTH_AND_COLOR = new RenderStateShard.WriteMaskStateShard(ENABLE_COLOUR_COMPONENTS_WRITING, ENABLE_DEPTH_WRITING);
COLOR_WRITE = new RenderStateShard.WriteMaskStateShard(true, false);
final LineStateShard LINE = new LineStateShard(OptionalDouble.of(2.0));
final int INITIAL_BUFFER_SIZE = 128;
RenderType.CompositeState renderState;
//LINES
// RenderSystem.pushLightingAttributes();
// RenderSystem.pushTextureAttributes();
// RenderSystem.disableCull();
// RenderSystem.disableLighting();
// RenderSystem.disableTexture();
//
// RenderSystem.enableBlend();
// RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//
// RenderSystem.lineWidth(2);
renderState = RenderType.CompositeState.builder()
.setLineState(new RenderStateShard.LineStateShard(OptionalDouble.of(2)))
.setLayeringState(PROJECTION_LAYERING)
renderState = CompositeState.builder()
.setLineState(LINE)
.setLayeringState(VIEW_OFFSET_Z_LAYERING)
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setWriteMaskState(WRITE_TO_DEPTH_AND_COLOR)
.setCullState(CULL_DISABLED)
.setWriteMaskState(COLOR_DEPTH_WRITE)
.setCullState(RenderStateShard.NO_CULL)
.createCompositeState(false);
LINES = RenderType.create("eb_lines",
DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.LINES, INITIAL_BUFFER_SIZE, false, false, renderState);
renderState = RenderType.CompositeState.builder()
.setLineState(new RenderStateShard.LineStateShard(OptionalDouble.of(2)))
.setLayeringState(PROJECTION_LAYERING)
//PLANES
renderState = CompositeState.builder()
.setLineState(LINE)
.setLayeringState(VIEW_OFFSET_Z_LAYERING)
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setWriteMaskState(COLOR_WRITE)
.setCullState(CULL_DISABLED)
.setCullState(RenderStateShard.NO_CULL)
.createCompositeState(false);
PLANES = RenderType.create("eb_planes",
DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.TRIANGLE_STRIP, INITIAL_BUFFER_SIZE, false, false, renderState);
}
public BuildRenderTypes(String p_173178_, VertexFormat p_173179_, VertexFormat.Mode p_173180_, int p_173181_, boolean p_173182_, boolean p_173183_, Runnable p_173184_, Runnable p_173185_) {
super(p_173178_, p_173179_, p_173180_, p_173181_, p_173182_, p_173183_, p_173184_, p_173185_);
}
public static RenderType getBlockPreviewRenderType(float dissolve, BlockPos blockPos, BlockPos firstPos,
@@ -113,8 +75,7 @@ public class BuildRenderTypes {
// RenderSystem.pushTextureAttributes();
ShaderHandler.useShader(ShaderHandler.dissolve, generateShaderCallback(dissolve, Vec3.atLowerCornerOf(blockPos), Vec3.atLowerCornerOf(firstPos), Vec3.atLowerCornerOf(secondPos), blockPos == secondPos, red));
//TODO 1.17
// RenderSystem.blendColor(1f, 1f, 1f, 0.8f);
RenderSystem.setShaderColor(1f, 1f, 1f, 0.8f);
}, ShaderHandler::releaseShader);
RenderType.CompositeState renderState = RenderType.CompositeState.builder()
@@ -203,43 +164,4 @@ public class BuildRenderTypes {
this.red = red;
}
}
// public static class MyTexturingState extends RenderState.TexturingState {
//
// public float dissolve;
// public Vector3d blockPos;
// public Vector3d firstPos;
// public Vector3d secondPos;
// public boolean highlight;
// public boolean red;
//
// public MyTexturingState(String p_i225989_1_, float dissolve, Vector3d blockPos, Vector3d firstPos,
// Vector3d secondPos, boolean highlight, boolean red, Runnable p_i225989_2_, Runnable p_i225989_3_) {
// super(p_i225989_1_, p_i225989_2_, p_i225989_3_);
// this.dissolve = dissolve;
// this.blockPos = blockPos;
// this.firstPos = firstPos;
// this.secondPos = secondPos;
// this.highlight = highlight;
// this.red = red;
// }
//
// @Override
// public boolean equals(Object p_equals_1_) {
// if (this == p_equals_1_) {
// return true;
// } else if (p_equals_1_ != null && this.getClass() == p_equals_1_.getClass()) {
// MyTexturingState other = (MyTexturingState)p_equals_1_;
// return this.dissolve == other.dissolve && this.blockPos == other.blockPos && this.firstPos == other.firstPos
// && this.secondPos == other.secondPos && this.highlight == other.highlight && this.red == other.red;
// } else {
// return false;
// }
// }
//
// @Override
// public int hashCode() {
//
// }
// }
}

View File

@@ -1,53 +1,32 @@
# This is an example mods.toml file. It contains the data relating to the loading mods.
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[34,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
modLoader="javafml"
# Forge for 1.17.1 is version 37
loaderVersion="[37,)"
license="GNU LESSER GENERAL PUBLIC LICENSE"
# A URL to refer people to when problems occur with this mod
issueTrackerURL="https://bitbucket.org/Requios/effortless-building/issues?status=new&status=open" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="effortlessbuilding" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
version="${file.jarVersion}" #mandatory
# A display name for the mod
displayName="Effortless Building" #mandatory
# A URL to query for updates for this mod. See the JSON update specification <here>
#updateJSONURL="example.com" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
displayURL="https://minecraft.curseforge.com/projects/effortless-building" #optional
# A file name (in the root of the mod JAR) containing a logo for display
logoFile="logo.png" #optional
# A text field displayed in the mod UI
credits="" #optional
# A text field displayed in the mod UI
authors="Requios" #optional
# The description text for the mod (multi line!) (#mandatory)
description='''
Makes building easier by providing tools like mirrors, arrays, QuickReplace and a block randomizer. For survival and creative mode.
'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.examplemod]] #optional
# the modid of the dependency
modId="forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
versionRange="[34,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
issueTrackerURL="https://bitbucket.org/Requios/effortless-building/issues?status=new&status=open"
showAsResourcePack=false
[[mods]]
modId="effortlessbuilding"
version="1.0.0.0"
displayName="Effortless Building"
displayURL="https://minecraft.curseforge.com/projects/effortless-building"
logoFile="logo.png"
credits=""
authors="Requios"
description='''
Makes building easier by providing tools like mirrors, arrays, build modes and a block randomizer. For survival and creative mode.
'''
[[dependencies.effortlessbuilding]]
modId="forge"
mandatory=true
versionRange="[37,)"
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
side="BOTH"
# Here's another dependency
[[dependencies.examplemod]]
[[dependencies.effortlessbuilding]]
modId="minecraft"
mandatory=true
versionRange="[1.16.3,1.17)"
versionRange="[1.17.1,1.18)"
ordering="NONE"
side="BOTH"