diff --git a/build.gradle b/build.gradle index f075063..604f0d2 100644 --- a/build.gradle +++ b/build.gradle @@ -97,13 +97,19 @@ dependencies { name : "forge", version: "${project.mcversion}-${project.forgeversion}" ]) - + /* compileOnly fg.deobf([ group: "vazkii.botania", name: "Botania", version: "${project.botania}", classifier: "api" - ]) + ])*/ + + runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.14.4-1.1-25.135") + runtimeOnly fg.deobf("top.theillusivec4.curios:curios:FORGE-1.14.4-1.0.6.1") + + compileOnly fg.deobf("vazkii.botania:Botania:r1.11-379.354:api") + runtimeOnly fg.deobf("vazkii.botania:Botania:r1.11-379.354") } jar { @@ -137,4 +143,4 @@ publishing { url "file:///${project.projectDir}/mcmodsrepo" } } -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index 6505f86..3343c58 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,11 +4,11 @@ org.gradle.daemon=false author=thetadev modid=constructionwand -mcversion=1.16.5 -forgeversion=36.0.46 -mcp_mappings=20200723-1.16.1 +mcversion=1.14.4 +forgeversion=28.2.23 +mcp_mappings=20190719-1.14.3 -botania=1.16.2-405 +botania=r1.11-379.354 version_major=2 -version_minor=0 \ No newline at end of file +version_minor=4 \ No newline at end of file diff --git a/src/generated/resources/data/constructionwand/advancements/recipes/tools/stone_wand.json b/src/generated/resources/data/constructionwand/advancements/recipes/tools/stone_wand.json index c31aa4d..5b07428 100644 --- a/src/generated/resources/data/constructionwand/advancements/recipes/tools/stone_wand.json +++ b/src/generated/resources/data/constructionwand/advancements/recipes/tools/stone_wand.json @@ -11,7 +11,7 @@ "conditions": { "items": [ { - "tag": "minecraft:stone_tool_materials" + "tag": "forge:cobblestone" } ] } diff --git a/src/generated/resources/data/constructionwand/recipes/stone_wand.json b/src/generated/resources/data/constructionwand/recipes/stone_wand.json index b4448d5..114881e 100644 --- a/src/generated/resources/data/constructionwand/recipes/stone_wand.json +++ b/src/generated/resources/data/constructionwand/recipes/stone_wand.json @@ -7,7 +7,7 @@ ], "key": { "X": { - "tag": "minecraft:stone_tool_materials" + "tag": "forge:cobblestone" }, "#": { "tag": "forge:rods/wooden" diff --git a/src/main/java/thetadev/constructionwand/ConstructionWand.java b/src/main/java/thetadev/constructionwand/ConstructionWand.java index 95e49de..ad3dfdf 100644 --- a/src/main/java/thetadev/constructionwand/ConstructionWand.java +++ b/src/main/java/thetadev/constructionwand/ConstructionWand.java @@ -82,7 +82,6 @@ public class ConstructionWand renderBlockPreview = new RenderBlockPreview(); MinecraftForge.EVENT_BUS.register(renderBlockPreview); MinecraftForge.EVENT_BUS.register(new ClientEvents()); - ModItems.registerModelProperties(); ModItems.registerItemColors(); } diff --git a/src/main/java/thetadev/constructionwand/basics/WandUtil.java b/src/main/java/thetadev/constructionwand/basics/WandUtil.java index 6f8a2fe..0c7abff 100644 --- a/src/main/java/thetadev/constructionwand/basics/WandUtil.java +++ b/src/main/java/thetadev/constructionwand/basics/WandUtil.java @@ -7,12 +7,9 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; -import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.state.Property; -import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.state.properties.SlabType; +import net.minecraft.item.Items; import net.minecraft.stats.Stats; import net.minecraft.util.Direction; import net.minecraft.util.EntityPredicates; @@ -21,8 +18,8 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.BlockSnapshot; @@ -62,12 +59,12 @@ public class WandUtil return new BlockPos(player.getPositionVec()); } - public static Vector3d entityPositionVec(Entity entity) { - return new Vector3d(entity.getPosX(), entity.getPosY() - entity.getYOffset() + entity.getHeight() / 2, entity.getPosZ()); + public static Vec3d entityPositionVec(Entity entity) { + return new Vec3d(entity.posX, entity.posY - entity.getYOffset() + entity.getHeight() / 2, entity.posZ); } - public static Vector3d blockPosVec(BlockPos pos) { - return new Vector3d(pos.getX(), pos.getY(), pos.getZ()); + public static Vec3d blockPosVec(BlockPos pos) { + return new Vec3d(pos.getX(), pos.getY(), pos.getZ()); } public static List getHotbar(PlayerEntity player) { @@ -110,17 +107,15 @@ public class WandUtil } public static boolean placeBlock(World world, PlayerEntity player, BlockState block, BlockPos pos, @Nullable BlockItem item) { - if(!world.setBlockState(pos, block)) { - ConstructionWand.LOGGER.info("Block could not be placed"); - return false; - } - - // Remove block if placeEvent is canceled - BlockSnapshot snapshot = BlockSnapshot.create(world.func_234923_W_(), world, pos); + // Abort if placeEvent is canceled + BlockSnapshot snapshot = new BlockSnapshot(world, pos, block); BlockEvent.EntityPlaceEvent placeEvent = new BlockEvent.EntityPlaceEvent(snapshot, block, player); MinecraftForge.EVENT_BUS.post(placeEvent); - if(placeEvent.isCanceled()) { - world.removeBlock(pos, false); + if(placeEvent.isCanceled()) return false; + + // Place the block + if(!world.setBlockState(pos, block)) { + ConstructionWand.LOGGER.info("Block could not be placed"); return false; } @@ -208,17 +203,23 @@ public class WandUtil /** * Tests if a wand can place a block at a certain position. - * This check is independent from the used block. + * This check is independent of the used block. */ public static boolean isPositionPlaceable(World world, PlayerEntity player, BlockPos pos, boolean replace) { - if(!isPositionModifiable(world,player, pos)) return false; + if(!isPositionModifiable(world, player, pos)) return false; // If replace mode is off, target has to be air - return replace || world.isAirBlock(pos); + if(world.isAirBlock(pos)) return true; + + // Otherwise, check if the block can be replaced by a generic block + return replace && world.getBlockState(pos).isReplaceable( + new WandItemUseContext(world, player, + new BlockRayTraceResult(new Vec3d(0, 0, 0), Direction.DOWN, pos, false), + pos, (BlockItem) Items.STONE)); } public static boolean isBlockRemovable(World world, PlayerEntity player, BlockPos pos) { - if(!isPositionModifiable(world,player, pos)) return false; + if(!isPositionModifiable(world, player, pos)) return false; if(!player.isCreative()) { return !(world.getBlockState(pos).getBlockHardness(world, pos) <= -1) && world.getTileEntity(pos) == null; @@ -226,6 +227,10 @@ public class WandUtil return true; } + public static boolean isBlockPermeable(World world, BlockPos pos) { + return world.isAirBlock(pos) || world.getBlockState(pos).getCollisionShape(world, pos).isEmpty(); + } + public static boolean entitiesCollidingWithBlock(World world, BlockState blockState, BlockPos pos) { VoxelShape shape = blockState.getCollisionShape(world, pos); if(!shape.isEmpty()) { @@ -235,7 +240,7 @@ public class WandUtil return false; } - public static Direction fromVector(Vector3d vector) { + public static Direction fromVector(Vec3d vector) { return Direction.getFacingFromVector(vector.x, vector.y, vector.z); } } diff --git a/src/main/java/thetadev/constructionwand/basics/option/WandUpgrades.java b/src/main/java/thetadev/constructionwand/basics/option/WandUpgrades.java index 19626c2..90cfacb 100644 --- a/src/main/java/thetadev/constructionwand/basics/option/WandUpgrades.java +++ b/src/main/java/thetadev/constructionwand/basics/option/WandUpgrades.java @@ -56,7 +56,8 @@ public class WandUpgrades for(T item : upgrades) { if(item == dval) continue; - listnbt.add(StringNBT.valueOf(item.getRegistryName().toString())); + listnbt.add(new StringNBT(item.getRegistryName().toString())); + } tag.put(key, listnbt); } diff --git a/src/main/java/thetadev/constructionwand/client/ClientEvents.java b/src/main/java/thetadev/constructionwand/client/ClientEvents.java index 954ace1..f956dcc 100644 --- a/src/main/java/thetadev/constructionwand/client/ClientEvents.java +++ b/src/main/java/thetadev/constructionwand/client/ClientEvents.java @@ -86,7 +86,7 @@ public class ClientEvents } private static boolean isKeyDown(int id) { - return InputMappings.isKeyDown(Minecraft.getInstance().getMainWindow().getHandle(), id); + return InputMappings.isKeyDown(Minecraft.getInstance().mainWindow.getHandle(), id); } public static boolean isOptKeyDown() { diff --git a/src/main/java/thetadev/constructionwand/client/RenderBlockPreview.java b/src/main/java/thetadev/constructionwand/client/RenderBlockPreview.java index c79006f..4e256b6 100644 --- a/src/main/java/thetadev/constructionwand/client/RenderBlockPreview.java +++ b/src/main/java/thetadev/constructionwand/client/RenderBlockPreview.java @@ -1,10 +1,8 @@ package thetadev.constructionwand.client; -import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -12,7 +10,7 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; -import net.minecraftforge.client.event.DrawHighlightEvent; +import net.minecraftforge.client.event.DrawBlockHighlightEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import thetadev.constructionwand.basics.WandUtil; import thetadev.constructionwand.items.wand.ItemWand; @@ -26,7 +24,7 @@ public class RenderBlockPreview public Set undoBlocks; @SubscribeEvent - public void renderBlockHighlight(DrawHighlightEvent event) { + public void renderBlockHighlight(DrawBlockHighlightEvent event) { if(event.getTarget().getType() != RayTraceResult.Type.BLOCK) return; BlockRayTraceResult rtr = (BlockRayTraceResult) event.getTarget(); @@ -52,7 +50,15 @@ public class RenderBlockPreview if(blocks == null || blocks.isEmpty()) return; - renderBlockList(blocks, event.getMatrix(), event.getBuffers(), colorR, colorG, colorB); + for(BlockPos block : blocks) { + double partialTicks = event.getPartialTicks(); + double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks; + double d1 = player.lastTickPosY + player.getEyeHeight() + (player.posY - player.lastTickPosY) * partialTicks; + double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks; + + AxisAlignedBB aabb = new AxisAlignedBB(block).offset(-d0, -d1, -d2); + drawBoundingBox(aabb, colorR, colorG, colorB, 0.4F); + } event.setCanceled(true); } @@ -61,19 +67,33 @@ public class RenderBlockPreview return rtr1.getPos().equals(rtr2.getPos()) && rtr1.getFace().equals(rtr2.getFace()); } - private void renderBlockList(Set blocks, MatrixStack ms, IRenderTypeBuffer buffer, float red, float green, float blue) { - double renderPosX = Minecraft.getInstance().getRenderManager().info.getProjectedView().getX(); - double renderPosY = Minecraft.getInstance().getRenderManager().info.getProjectedView().getY(); - double renderPosZ = Minecraft.getInstance().getRenderManager().info.getProjectedView().getZ(); + private static void drawBoundingBox(AxisAlignedBB box, float red, float green, float blue, float alpha) { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuffer(); + buffer.begin(3, DefaultVertexFormats.POSITION_COLOR); - ms.push(); - ms.translate(-renderPosX, -renderPosY, -renderPosZ); + //Base + buffer.pos(box.minX, box.minY, box.minZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.maxX, box.minY, box.minZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.maxX, box.minY, box.maxZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.minX, box.minY, box.maxZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.minX, box.minY, box.minZ).color(red, green, blue, alpha).endVertex(); + //Side1 + buffer.pos(box.minX, box.maxY, box.minZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.minX, box.maxY, box.maxZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.minX, box.minY, box.maxZ).color(red, green, blue, alpha).endVertex(); + //Side2 + buffer.pos(box.minX, box.maxY, box.maxZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.maxX, box.maxY, box.maxZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.maxX, box.minY, box.maxZ).color(red, green, blue, alpha).endVertex(); + //Side3 + buffer.pos(box.maxX, box.maxY, box.maxZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.maxX, box.maxY, box.minZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.maxX, box.minY, box.minZ).color(red, green, blue, alpha).endVertex(); + //Side4 + buffer.pos(box.maxX, box.maxY, box.minZ).color(red, green, blue, alpha).endVertex(); + buffer.pos(box.minX, box.maxY, box.minZ).color(red, green, blue, alpha).endVertex(); - for(BlockPos block : blocks) { - AxisAlignedBB aabb = new AxisAlignedBB(block); - IVertexBuilder lineBuilder = buffer.getBuffer(RenderTypes.TRANSLUCENT_LINES); - WorldRenderer.drawBoundingBox(ms, lineBuilder, aabb, red, green, blue, 0.4F); - } - ms.pop(); + tessellator.draw(); } } diff --git a/src/main/java/thetadev/constructionwand/client/RenderTypes.java b/src/main/java/thetadev/constructionwand/client/RenderTypes.java deleted file mode 100644 index c901bd3..0000000 --- a/src/main/java/thetadev/constructionwand/client/RenderTypes.java +++ /dev/null @@ -1,37 +0,0 @@ -package thetadev.constructionwand.client; - -import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.renderer.RenderState; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import org.lwjgl.opengl.GL11; -import thetadev.constructionwand.ConstructionWand; - -import java.util.OptionalDouble; - -public class RenderTypes -{ - public static final RenderType TRANSLUCENT_LINES; - - protected static final RenderState.TransparencyState TRANSLUCENT_TRANSPARENCY = new RenderState.TransparencyState("translucent_transparency", () -> { - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - }, RenderSystem::disableBlend); - protected static final RenderState.DepthTestState DEPTH_ALWAYS = new RenderState.DepthTestState("always", GL11.GL_ALWAYS); - - static { - RenderType.State translucentNoDepthState = RenderType.State.getBuilder().transparency(TRANSLUCENT_TRANSPARENCY) - .line(new RenderState.LineState(OptionalDouble.of(2))) - .texture(new RenderState.TextureState()) - .depthTest(DEPTH_ALWAYS) - .build(false); - - TRANSLUCENT_LINES = RenderType.makeType( - ConstructionWand.MODID + ":translucent_lines", - DefaultVertexFormats.POSITION_COLOR, - GL11.GL_LINES, - 256, - translucentNoDepthState - ); - } -} diff --git a/src/main/java/thetadev/constructionwand/client/ScreenWand.java b/src/main/java/thetadev/constructionwand/client/ScreenWand.java index b987e49..489f98a 100644 --- a/src/main/java/thetadev/constructionwand/client/ScreenWand.java +++ b/src/main/java/thetadev/constructionwand/client/ScreenWand.java @@ -1,6 +1,5 @@ package thetadev.constructionwand.client; -import com.mojang.blaze3d.matrix.MatrixStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.button.Button; @@ -13,12 +12,13 @@ import thetadev.constructionwand.basics.option.IOption; import thetadev.constructionwand.basics.option.WandOptions; import thetadev.constructionwand.network.PacketWandOption; -import javax.annotation.Nonnull; +import java.util.HashMap; public class ScreenWand extends Screen { private final ItemStack wand; private final WandOptions wandOptions; + private final HashMap, Button> optionButtons; private static final int BUTTON_WIDTH = 160; private static final int BUTTON_HEIGHT = 20; @@ -34,11 +34,13 @@ public class ScreenWand extends Screen super(new StringTextComponent("ScreenWand")); this.wand = wand; wandOptions = new WandOptions(wand); + optionButtons = new HashMap<>(); } @Override - public void init(@Nonnull Minecraft minecraft, int width, int height) { + public void init(Minecraft minecraft, int width, int height) { super.init(minecraft, width, height); + optionButtons.clear(); createButton(0, 0, wandOptions.cores); createButton(0, 1, wandOptions.lock); @@ -49,33 +51,35 @@ public class ScreenWand extends Screen } @Override - public void render(@Nonnull MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - renderBackground(matrixStack); - super.render(matrixStack, mouseX, mouseY, partialTicks); - drawCenteredString(matrixStack, font, wand.getDisplayName(), width / 2, height / 2 - FIELD_HEIGHT / 2 - SPACING_HEIGHT, 16777215); + public void render(int mouseX, int mouseY, float partialTicks) { + renderBackground(); + super.render(mouseX, mouseY, partialTicks); + drawCenteredString(font, wand.getDisplayName().getFormattedText(), width / 2, height / 2 - FIELD_HEIGHT / 2 - SPACING_HEIGHT, 16777215); + optionButtons.forEach((opt, but) -> drawTooltip(mouseX, mouseY, opt, but)); } @Override public boolean charTyped(char character, int code) { - if(character == 'e') closeScreen(); + if(character == 'e') onClose(); return super.charTyped(character, code); } private void createButton(int cx, int cy, IOption option) { - Button button = new Button(getX(cx), getY(cy), BUTTON_WIDTH, BUTTON_HEIGHT, getButtonLabel(option), bt -> clickButton(bt, option), (bt, ms, x, y) -> drawTooltip(ms, x, y, option)); + Button button = new Button(getX(cx), getY(cy), BUTTON_WIDTH, BUTTON_HEIGHT, getButtonLabel(option).getFormattedText(), bt -> clickButton(bt, option)); button.active = option.isEnabled(); addButton(button); + optionButtons.put(option, button); } private void clickButton(Button button, IOption option) { option.next(); ConstructionWand.instance.HANDLER.sendToServer(new PacketWandOption(option, false)); - button.setMessage(getButtonLabel(option)); + button.setMessage(getButtonLabel(option).getFormattedText()); } - private void drawTooltip(MatrixStack matrixStack, int mouseX, int mouseY, IOption option) { - if(isMouseOver(mouseX, mouseY)) { - renderTooltip(matrixStack, new TranslationTextComponent(option.getDescTranslation()), mouseX, mouseY); + private void drawTooltip(int mouseX, int mouseY, IOption option, Button button) { + if(button.isHovered()) { + renderTooltip(new TranslationTextComponent(option.getDescTranslation()).getFormattedText(), mouseX, mouseY); } } @@ -88,6 +92,6 @@ public class ScreenWand extends Screen } private ITextComponent getButtonLabel(IOption option) { - return new TranslationTextComponent(option.getKeyTranslation()).append(new TranslationTextComponent(option.getValueTranslation())); + return new TranslationTextComponent(option.getKeyTranslation()).appendSibling(new TranslationTextComponent(option.getValueTranslation())); } } diff --git a/src/main/java/thetadev/constructionwand/data/ICustomItemModel.java b/src/main/java/thetadev/constructionwand/data/ICustomItemModel.java deleted file mode 100644 index 6d7d3e2..0000000 --- a/src/main/java/thetadev/constructionwand/data/ICustomItemModel.java +++ /dev/null @@ -1,6 +0,0 @@ -package thetadev.constructionwand.data; - -public interface ICustomItemModel -{ - void generateCustomItemModel(ItemModelGenerator generator, String name); -} diff --git a/src/main/java/thetadev/constructionwand/data/Inp.java b/src/main/java/thetadev/constructionwand/data/Inp.java index cab5dbf..041c20d 100644 --- a/src/main/java/thetadev/constructionwand/data/Inp.java +++ b/src/main/java/thetadev/constructionwand/data/Inp.java @@ -3,7 +3,7 @@ package thetadev.constructionwand.data; import net.minecraft.advancements.criterion.ItemPredicate; import net.minecraft.item.Item; import net.minecraft.item.crafting.Ingredient; -import net.minecraft.tags.ITag; +import net.minecraft.tags.Tag; import net.minecraft.util.IItemProvider; public class Inp @@ -22,7 +22,7 @@ public class Inp return new Inp(in.asItem().getRegistryName().getPath(), Ingredient.fromItems(in), ItemPredicate.Builder.create().item(in).build()); } - public static Inp fromTag(ITag.INamedTag in) { - return new Inp(in.getName().getPath(), Ingredient.fromTag(in), ItemPredicate.Builder.create().tag(in).build()); + public static Inp fromTag(Tag in) { + return new Inp(in.getId().getPath(), Ingredient.fromTag(in), ItemPredicate.Builder.create().tag(in).build()); } } \ No newline at end of file diff --git a/src/main/java/thetadev/constructionwand/data/ItemModelGenerator.java b/src/main/java/thetadev/constructionwand/data/ItemModelGenerator.java deleted file mode 100644 index 507bc4b..0000000 --- a/src/main/java/thetadev/constructionwand/data/ItemModelGenerator.java +++ /dev/null @@ -1,37 +0,0 @@ -package thetadev.constructionwand.data; - -import net.minecraft.data.DataGenerator; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraftforge.client.model.generators.ItemModelProvider; -import net.minecraftforge.common.data.ExistingFileHelper; -import thetadev.constructionwand.ConstructionWand; -import thetadev.constructionwand.items.ModItems; - -import javax.annotation.Nonnull; - -public class ItemModelGenerator extends ItemModelProvider -{ - public ItemModelGenerator(DataGenerator generator, ExistingFileHelper existingFileHelper) { - super(generator, ConstructionWand.MODID, existingFileHelper); - } - - @Override - protected void registerModels() { - for(Item item : ModItems.ALL_ITEMS) { - String name = item.getRegistryName().getPath(); - - if(item instanceof ICustomItemModel) - ((ICustomItemModel) item).generateCustomItemModel(this, name); - else if(item instanceof BlockItem) - withExistingParent(name, modLoc("block/" + name)); - else withExistingParent(name, "item/generated").texture("layer0", "item/" + name); - } - } - - @Nonnull - @Override - public String getName() { - return ConstructionWand.MODNAME + " item models"; - } -} diff --git a/src/main/java/thetadev/constructionwand/data/ModData.java b/src/main/java/thetadev/constructionwand/data/ModData.java index 45ccd4a..15482ad 100644 --- a/src/main/java/thetadev/constructionwand/data/ModData.java +++ b/src/main/java/thetadev/constructionwand/data/ModData.java @@ -1,7 +1,7 @@ package thetadev.constructionwand.data; import net.minecraft.data.DataGenerator; -import net.minecraftforge.common.data.ExistingFileHelper; +import net.minecraftforge.client.model.generators.ExistingFileHelper; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.GatherDataEvent; @@ -17,9 +17,5 @@ public class ModData if(event.includeServer()) { generator.addProvider(new RecipeGenerator(generator)); } - - if(event.includeClient()) { - generator.addProvider(new ItemModelGenerator(generator, fileHelper)); - } } } diff --git a/src/main/java/thetadev/constructionwand/data/RecipeGenerator.java b/src/main/java/thetadev/constructionwand/data/RecipeGenerator.java index 649fcce..1e7f08d 100644 --- a/src/main/java/thetadev/constructionwand/data/RecipeGenerator.java +++ b/src/main/java/thetadev/constructionwand/data/RecipeGenerator.java @@ -3,7 +3,6 @@ package thetadev.constructionwand.data; import net.minecraft.data.*; import net.minecraft.item.Items; import net.minecraft.item.crafting.SpecialRecipeSerializer; -import net.minecraft.tags.ItemTags; import net.minecraft.util.IItemProvider; import net.minecraft.util.ResourceLocation; import net.minecraft.util.registry.Registry; @@ -23,7 +22,7 @@ public class RecipeGenerator extends RecipeProvider @Override protected void registerRecipes(@Nonnull Consumer consumer) { - wandRecipe(consumer, ModItems.WAND_STONE, Inp.fromTag(ItemTags.field_232909_aa_)); //stone_tool_materials + wandRecipe(consumer, ModItems.WAND_STONE, Inp.fromTag(Tags.Items.COBBLESTONE)); wandRecipe(consumer, ModItems.WAND_IRON, Inp.fromTag(Tags.Items.INGOTS_IRON)); wandRecipe(consumer, ModItems.WAND_DIAMOND, Inp.fromTag(Tags.Items.GEMS_DIAMOND)); wandRecipe(consumer, ModItems.WAND_INFINITY, Inp.fromTag(Tags.Items.NETHER_STARS)); @@ -59,7 +58,7 @@ public class RecipeGenerator extends RecipeProvider private void specialRecipe(Consumer consumer, SpecialRecipeSerializer serializer) { ResourceLocation name = Registry.RECIPE_SERIALIZER.getKey(serializer); - CustomRecipeBuilder.customRecipe(serializer).build(consumer, ConstructionWand.loc("dynamic/" + name.getPath()).toString()); + CustomRecipeBuilder.func_218656_a(serializer).build(consumer, ConstructionWand.loc("dynamic/" + name.getPath()).toString()); } @Nonnull diff --git a/src/main/java/thetadev/constructionwand/items/ModItems.java b/src/main/java/thetadev/constructionwand/items/ModItems.java index 43408dd..151e1b7 100644 --- a/src/main/java/thetadev/constructionwand/items/ModItems.java +++ b/src/main/java/thetadev/constructionwand/items/ModItems.java @@ -4,7 +4,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.color.ItemColors; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemModelsProperties; import net.minecraft.item.ItemTier; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraftforge.api.distmarker.Dist; @@ -74,17 +73,6 @@ public class ModItems register(r, "wand_upgrade", RecipeWandUpgrade.SERIALIZER); } - @OnlyIn(Dist.CLIENT) - public static void registerModelProperties() { - for(Item item : WANDS) { - ItemModelsProperties.func_239418_a_( - item, ConstructionWand.loc("using_core"), - (stack, world, entity) -> entity == null || !(stack.getItem() instanceof ItemWand) ? 0 : - new WandOptions(stack).cores.get().getColor() > -1 ? 1 : 0 - ); - } - } - @OnlyIn(Dist.CLIENT) public static void registerItemColors() { ItemColors colors = Minecraft.getInstance().getItemColors(); diff --git a/src/main/java/thetadev/constructionwand/items/core/ItemCore.java b/src/main/java/thetadev/constructionwand/items/core/ItemCore.java index 4df952d..011cc95 100644 --- a/src/main/java/thetadev/constructionwand/items/core/ItemCore.java +++ b/src/main/java/thetadev/constructionwand/items/core/ItemCore.java @@ -24,8 +24,8 @@ public abstract class ItemCore extends ItemBase implements IWandCore @OnlyIn(Dist.CLIENT) public void addInformation(@Nonnull ItemStack itemstack, World worldIn, @Nonnull List lines, @Nonnull ITooltipFlag extraInfo) { lines.add(new TranslationTextComponent(ConstructionWand.MODID + ".option.cores." + getRegistryName().toString() + ".desc") - .mergeStyle(TextFormatting.GRAY)); + .applyTextStyle(TextFormatting.GRAY)); lines.add(new TranslationTextComponent(ConstructionWand.MODID + ".tooltip.core_tip") - .mergeStyle(TextFormatting.AQUA)); + .applyTextStyle(TextFormatting.AQUA)); } } diff --git a/src/main/java/thetadev/constructionwand/items/wand/ItemWand.java b/src/main/java/thetadev/constructionwand/items/wand/ItemWand.java index 6cc75a9..d17425a 100644 --- a/src/main/java/thetadev/constructionwand/items/wand/ItemWand.java +++ b/src/main/java/thetadev/constructionwand/items/wand/ItemWand.java @@ -9,6 +9,7 @@ import net.minecraft.item.ItemUseContext; import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; @@ -17,14 +18,11 @@ import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.model.generators.ModelFile; import thetadev.constructionwand.ConstructionWand; import thetadev.constructionwand.api.IWandCore; import thetadev.constructionwand.basics.WandUtil; import thetadev.constructionwand.basics.option.IOption; import thetadev.constructionwand.basics.option.WandOptions; -import thetadev.constructionwand.data.ICustomItemModel; -import thetadev.constructionwand.data.ItemModelGenerator; import thetadev.constructionwand.items.ItemBase; import thetadev.constructionwand.wand.WandJob; @@ -32,10 +30,13 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; -public abstract class ItemWand extends ItemBase implements ICustomItemModel +public abstract class ItemWand extends ItemBase { public ItemWand(String name, Properties properties) { super(name, properties); + addPropertyOverride(new ResourceLocation(ConstructionWand.MODID, "using_core"), + (stack, world, entity) -> entity == null || !(stack.getItem() instanceof ItemWand) ? 0 : + new WandOptions(stack).cores.get().getColor() > -1 ? 1 : 0); } @Nonnull @@ -64,14 +65,14 @@ public abstract class ItemWand extends ItemBase implements ICustomItemModel ItemStack stack = player.getHeldItem(hand); if(!player.isSneaking()) { - if(world.isRemote) return ActionResult.resultFail(stack); + if(world.isRemote) return new ActionResult<>(ActionResultType.FAIL, stack); // Right click: Place angel block WandJob job = getWandJob(player, world, BlockRayTraceResult.createMiss(player.getLookVec(), WandUtil.fromVector(player.getLookVec()), WandUtil.playerPos(player)), stack); - return job.doIt() ? ActionResult.resultSuccess(stack) : ActionResult.resultFail(stack); + return new ActionResult<>(job.doIt() ? ActionResultType.SUCCESS : ActionResultType.FAIL, stack); } - return ActionResult.resultFail(stack); + return new ActionResult<>(ActionResultType.FAIL, stack); } public static WandJob getWandJob(PlayerEntity player, World world, @Nullable BlockRayTraceResult rayTraceResult, ItemStack wand) { @@ -106,13 +107,13 @@ public abstract class ItemWand extends ItemBase implements ICustomItemModel if(Screen.hasShiftDown()) { for(int i = 1; i < options.allOptions.length; i++) { IOption opt = options.allOptions[i]; - lines.add(new TranslationTextComponent(opt.getKeyTranslation()).mergeStyle(TextFormatting.AQUA) - .append(new TranslationTextComponent(opt.getValueTranslation()).mergeStyle(TextFormatting.GRAY)) + lines.add(new TranslationTextComponent(opt.getKeyTranslation()).applyTextStyle(TextFormatting.AQUA) + .appendSibling(new TranslationTextComponent(opt.getValueTranslation()).applyTextStyle(TextFormatting.GRAY)) ); } if(!options.cores.getUpgrades().isEmpty()) { lines.add(new StringTextComponent("")); - lines.add(new TranslationTextComponent(langTooltip + "cores").mergeStyle(TextFormatting.GRAY)); + lines.add(new TranslationTextComponent(langTooltip + "cores").applyTextStyle(TextFormatting.GRAY)); for(IWandCore core : options.cores.getUpgrades()) { lines.add(new TranslationTextComponent(options.cores.getKeyTranslation() + "." + core.getRegistryName().toString())); @@ -122,33 +123,19 @@ public abstract class ItemWand extends ItemBase implements ICustomItemModel // Default tooltip: show block limit + active wand core else { IOption opt = options.allOptions[0]; - lines.add(new TranslationTextComponent(langTooltip + "blocks", limit).mergeStyle(TextFormatting.GRAY)); - lines.add(new TranslationTextComponent(opt.getKeyTranslation()).mergeStyle(TextFormatting.AQUA) - .append(new TranslationTextComponent(opt.getValueTranslation()).mergeStyle(TextFormatting.WHITE))); - lines.add(new TranslationTextComponent(langTooltip + "shift").mergeStyle(TextFormatting.AQUA)); + lines.add(new TranslationTextComponent(langTooltip + "blocks", limit).applyTextStyle(TextFormatting.GRAY)); + lines.add(new TranslationTextComponent(opt.getKeyTranslation()).applyTextStyle(TextFormatting.AQUA) + .appendSibling(new TranslationTextComponent(opt.getValueTranslation()).applyTextStyle(TextFormatting.WHITE))); + lines.add(new TranslationTextComponent(langTooltip + "shift").applyTextStyle(TextFormatting.AQUA)); } } public static void optionMessage(PlayerEntity player, IOption option) { player.sendStatusMessage( - new TranslationTextComponent(option.getKeyTranslation()).mergeStyle(TextFormatting.AQUA) - .append(new TranslationTextComponent(option.getValueTranslation()).mergeStyle(TextFormatting.WHITE)) - .append(new StringTextComponent(" - ").mergeStyle(TextFormatting.GRAY)) - .append(new TranslationTextComponent(option.getDescTranslation()).mergeStyle(TextFormatting.WHITE)) + new TranslationTextComponent(option.getKeyTranslation()).applyTextStyle(TextFormatting.AQUA) + .appendSibling(new TranslationTextComponent(option.getValueTranslation()).applyTextStyle(TextFormatting.WHITE)) + .appendSibling(new StringTextComponent(" - ").applyTextStyle(TextFormatting.GRAY)) + .appendSibling(new TranslationTextComponent(option.getDescTranslation()).applyTextStyle(TextFormatting.WHITE)) , true); } - - @Override - public void generateCustomItemModel(ItemModelGenerator generator, String name) { - ModelFile wandWithCore = generator.withExistingParent(name + "_core", "item/handheld") - .texture("layer0", generator.modLoc("item/" + name)) - .texture("layer1", generator.modLoc("item/overlay_core")); - - generator.withExistingParent(name, "item/handheld") - .texture("layer0", generator.modLoc("item/" + name)) - .override() - .predicate(generator.modLoc("using_core"), 1) - .model(wandWithCore).end(); - - } } diff --git a/src/main/java/thetadev/constructionwand/items/wand/ItemWandInfinity.java b/src/main/java/thetadev/constructionwand/items/wand/ItemWandInfinity.java index f53cb39..5df0e5d 100644 --- a/src/main/java/thetadev/constructionwand/items/wand/ItemWandInfinity.java +++ b/src/main/java/thetadev/constructionwand/items/wand/ItemWandInfinity.java @@ -4,6 +4,6 @@ package thetadev.constructionwand.items.wand; public class ItemWandInfinity extends ItemWand { public ItemWandInfinity(String name, Properties properties) { - super(name, properties.maxStackSize(1).isBurnable()); + super(name, properties.maxStackSize(1)); } } diff --git a/src/main/java/thetadev/constructionwand/wand/WandItemUseContext.java b/src/main/java/thetadev/constructionwand/wand/WandItemUseContext.java index b8c08f7..e5e492c 100644 --- a/src/main/java/thetadev/constructionwand/wand/WandItemUseContext.java +++ b/src/main/java/thetadev/constructionwand/wand/WandItemUseContext.java @@ -7,7 +7,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import thetadev.constructionwand.basics.WandUtil; @@ -18,10 +18,10 @@ public class WandItemUseContext extends BlockItemUseContext new BlockRayTraceResult(getBlockHitVec(rayTraceResult, pos), rayTraceResult.getFace(), pos, false)); } - private static Vector3d getBlockHitVec(BlockRayTraceResult rayTraceResult, BlockPos pos) { - Vector3d hitVec = rayTraceResult.getHitVec(); // Absolute coords of hit target + private static Vec3d getBlockHitVec(BlockRayTraceResult rayTraceResult, BlockPos pos) { + Vec3d hitVec = rayTraceResult.getHitVec(); // Absolute coords of hit target - Vector3d blockDelta = WandUtil.blockPosVec(rayTraceResult.getPos()).subtract(WandUtil.blockPosVec(pos)); // Vector between start and current block + Vec3d blockDelta = WandUtil.blockPosVec(rayTraceResult.getPos()).subtract(WandUtil.blockPosVec(pos)); // Vector between start and current block return blockDelta.add(hitVec); // Absolute coords of current block hit target } diff --git a/src/main/java/thetadev/constructionwand/wand/action/ActionAngel.java b/src/main/java/thetadev/constructionwand/wand/action/ActionAngel.java index f333d99..2847af4 100644 --- a/src/main/java/thetadev/constructionwand/wand/action/ActionAngel.java +++ b/src/main/java/thetadev/constructionwand/wand/action/ActionAngel.java @@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import thetadev.constructionwand.api.IWandAction; import thetadev.constructionwand.api.IWandSupplier; @@ -57,9 +57,9 @@ public class ActionAngel implements IWandAction if(!player.isCreative() && !ConfigServer.ANGEL_FALLING.get() && player.fallDistance > 10) return placeSnapshots; - Vector3d playerVec = WandUtil.entityPositionVec(player); - Vector3d lookVec = player.getLookVec().mul(2, 2, 2); - Vector3d placeVec = playerVec.add(lookVec); + Vec3d playerVec = WandUtil.entityPositionVec(player); + Vec3d lookVec = player.getLookVec().mul(2, 2, 2); + Vec3d placeVec = playerVec.add(lookVec); BlockPos currentPos = new BlockPos(placeVec); diff --git a/src/main/java/thetadev/constructionwand/wand/action/ActionDestruction.java b/src/main/java/thetadev/constructionwand/wand/action/ActionDestruction.java index 72340fd..5364101 100644 --- a/src/main/java/thetadev/constructionwand/wand/action/ActionDestruction.java +++ b/src/main/java/thetadev/constructionwand/wand/action/ActionDestruction.java @@ -39,14 +39,14 @@ public class ActionDestruction implements IWandAction HashSet allCandidates = new HashSet<>(); // Block face the wand was pointed at - Direction breakDirection = rayTraceResult.getFace(); + Direction breakFace = rayTraceResult.getFace(); // Block the wand was pointed at BlockPos startingPoint = rayTraceResult.getPos(); BlockState targetBlock = world.getBlockState(rayTraceResult.getPos()); // Is break direction allowed by lock? // Tried to break blocks from top/bottom face, so the wand should allow breaking in NS/EW direction - if(breakDirection == Direction.UP || breakDirection == Direction.DOWN) { + if(breakFace == Direction.UP || breakFace == Direction.DOWN) { if(options.testLock(WandOptions.LOCK.NORTHSOUTH) || options.testLock(WandOptions.LOCK.EASTWEST)) candidates.add(startingPoint); } @@ -57,6 +57,10 @@ public class ActionDestruction implements IWandAction // Process current candidates, stop when none are avaiable or block limit is reached while(!candidates.isEmpty() && destroySnapshots.size() < limit) { BlockPos currentCandidate = candidates.removeFirst(); + + // Only break blocks facing the player, with no collidable blocks in between + if(!WandUtil.isBlockPermeable(world, currentCandidate.offset(breakFace))) continue; + try { BlockState candidateBlock = world.getBlockState(currentCandidate); @@ -67,7 +71,7 @@ public class ActionDestruction implements IWandAction if(snapshot == null) continue; destroySnapshots.add(snapshot); - switch(breakDirection) { + switch(breakFace) { case DOWN: case UP: if(options.testLock(WandOptions.LOCK.NORTHSOUTH)) { diff --git a/src/main/java/thetadev/constructionwand/wand/supplier/SupplierInventory.java b/src/main/java/thetadev/constructionwand/wand/supplier/SupplierInventory.java index 19105de..2480d9b 100644 --- a/src/main/java/thetadev/constructionwand/wand/supplier/SupplierInventory.java +++ b/src/main/java/thetadev/constructionwand/wand/supplier/SupplierInventory.java @@ -5,6 +5,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; @@ -51,7 +52,7 @@ public class SupplierInventory implements IWandSupplier addBlockItem((BlockItem) offhandStack.getItem()); } // Otherwise use target block - else { + else if(target != null && target != Items.AIR) { addBlockItem(target); // Add replacement items diff --git a/src/main/java/thetadev/constructionwand/wand/undo/DestroySnapshot.java b/src/main/java/thetadev/constructionwand/wand/undo/DestroySnapshot.java index af62703..20ac265 100644 --- a/src/main/java/thetadev/constructionwand/wand/undo/DestroySnapshot.java +++ b/src/main/java/thetadev/constructionwand/wand/undo/DestroySnapshot.java @@ -2,7 +2,6 @@ package thetadev.constructionwand.wand.undo; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; @@ -59,8 +58,8 @@ public class DestroySnapshot implements ISnapshot // Ignore blocks and entities when in creative if(player.isCreative()) return true; - // Is block empty or fluid? - if(!world.isAirBlock(pos) && !world.getBlockState(pos).isReplaceable(Fluids.EMPTY)) return false; + // Is block empty? + if(!world.isAirBlock(pos)) return false; return !WandUtil.entitiesCollidingWithBlock(world, block, pos); } diff --git a/src/main/java/thetadev/constructionwand/wand/undo/PlaceSnapshot.java b/src/main/java/thetadev/constructionwand/wand/undo/PlaceSnapshot.java index 63fae19..ed64f8f 100644 --- a/src/main/java/thetadev/constructionwand/wand/undo/PlaceSnapshot.java +++ b/src/main/java/thetadev/constructionwand/wand/undo/PlaceSnapshot.java @@ -92,8 +92,8 @@ public class PlaceSnapshot implements ISnapshot @SuppressWarnings({"rawtypes", "unchecked"}) @Nullable private static BlockState getPlaceBlockstate(World world, PlayerEntity player, BlockRayTraceResult rayTraceResult, - BlockPos pos, BlockItem item, - @Nullable BlockState supportingBlock, boolean targetMode) { + BlockPos pos, BlockItem item, + @Nullable BlockState supportingBlock, boolean targetMode) { // Is block at pos replaceable? BlockItemUseContext ctx = new WandItemUseContext(world, player, rayTraceResult, pos, item); if(!ctx.canPlace()) return null; @@ -119,13 +119,13 @@ public class PlaceSnapshot implements ISnapshot for(Property property : new Property[]{ BlockStateProperties.HORIZONTAL_FACING, BlockStateProperties.FACING, BlockStateProperties.FACING_EXCEPT_UP, BlockStateProperties.ROTATION_0_15, BlockStateProperties.AXIS, BlockStateProperties.HALF, BlockStateProperties.STAIRS_SHAPE}) { - if(supportingBlock.hasProperty(property) && blockState.hasProperty(property)) { + if(supportingBlock.has(property) && blockState.has(property)) { blockState = blockState.with(property, supportingBlock.get(property)); } } // Dont dupe double slabs - if(supportingBlock.hasProperty(BlockStateProperties.SLAB_TYPE) && blockState.hasProperty(BlockStateProperties.SLAB_TYPE)) { + if(supportingBlock.has(BlockStateProperties.SLAB_TYPE) && blockState.has(BlockStateProperties.SLAB_TYPE)) { SlabType slabType = supportingBlock.get(BlockStateProperties.SLAB_TYPE); if(slabType != SlabType.DOUBLE) blockState = blockState.with(BlockStateProperties.SLAB_TYPE, slabType); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index e3238ee..0fb0406 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,6 +1,6 @@ modLoader="javafml" -loaderVersion="[33,)" license="MIT License" +loaderVersion="[28,)" [[mods]] modId="constructionwand" version="${file.jarVersion}" @@ -20,12 +20,12 @@ This is my first minecraft mod. May the odds be ever in your favor. [[dependencies.constructionwand]] modId="forge" mandatory=true - versionRange="[33,)" + versionRange="[28,)" ordering="NONE" side="BOTH" [[dependencies.constructionwand]] modId="minecraft" mandatory=true - versionRange="[1.16.2, 1.16.5]" + versionRange="[1.14.4]" ordering="NONE" side="BOTH"