diff --git a/build.gradle b/build.gradle index 3b85fffed..07066a4bf 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = 'mc1.14.4_v0.2.2b' +version = 'mc1.14.4_v0.2.3' group = 'com.simibubi.create' archivesBaseName = 'create' diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index fd8034a12..24df8e14d 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -75,8 +75,8 @@ public enum AllItems { ZINC_INGOT(new TaggedItem().withForgeTags("ingots/zinc")), BRASS_INGOT(new TaggedItem().withForgeTags("ingots/brass")), - SAND_PAPER(SandPaperItem::new), - RED_SAND_PAPER(SandPaperItem::new), + FLOUR, + DOUGH, OBSIDIAN_DUST, ROSE_QUARTZ, POLISHED_ROSE_QUARTZ, @@ -86,21 +86,17 @@ public enum AllItems { ELECTRON_TUBE, INTEGRATED_CIRCUIT, - __SCHEMATICS__(module()), - EMPTY_BLUEPRINT(Item::new, stackSize(1)), - BLUEPRINT_AND_QUILL(SchematicAndQuillItem::new, stackSize(1)), - BLUEPRINT(SchematicItem::new), - __CONTRAPTIONS__(module()), BELT_CONNECTOR(BeltConnectorItem::new), VERTICAL_GEARBOX(VerticalGearboxItem::new), - FLOUR, - DOUGH, PROPELLER, WHISK, BRASS_HAND, SLOT_COVER, - ZINC_HANDLE, + SUPER_GLUE, + ANTIOXIDANT, + SAND_PAPER(SandPaperItem::new), + RED_SAND_PAPER(SandPaperItem::new), WRENCH(WrenchItem::new), GOGGLES(GogglesItem::new), @@ -114,6 +110,7 @@ public enum AllItems { TERRAIN_ZAPPER(TerrainzapperItem::new), DEFORESTER(DeforesterItem::new), SYMMETRY_WAND(SymmetryWandItem::new), + ZINC_HANDLE, BLAZING_PICKAXE(p -> new BlazingToolItem(1, -2.8F, p, PICKAXE)), BLAZING_SHOVEL(p -> new BlazingToolItem(1.5F, -3.0F, p, SHOVEL)), @@ -129,6 +126,11 @@ public enum AllItems { SHADOW_STEEL_MATTOCK(p -> new ShadowSteelToolItem(2.5F, -1.5F, p, SHOVEL, AXE, HOE)), SHADOW_STEEL_SWORD(p -> new SwordItem(AllToolTiers.SHADOW_STEEL, 3, -2.0F, p)), + __SCHEMATICS__(module()), + EMPTY_BLUEPRINT(Item::new, stackSize(1)), + BLUEPRINT_AND_QUILL(SchematicAndQuillItem::new, stackSize(1)), + BLUEPRINT(SchematicItem::new), + ; private static class CategoryTracker { @@ -197,7 +199,8 @@ public enum AllItems { continue; entry.item = entry.taggedItem.getItemSupplier().apply(new Properties()); - entry.item = entry.taggedItem.getItemSupplier().apply(entry.specialProperties.apply(defaultProperties(entry))); + entry.item = + entry.taggedItem.getItemSupplier().apply(entry.specialProperties.apply(defaultProperties(entry))); entry.item.setRegistryName(Create.ID, Lang.asId(entry.name())); registry.register(entry.item); } @@ -226,11 +229,11 @@ public enum AllItems { private Set tagSetItem = new HashSet<>(); private Function itemSupplier; - public TaggedItem(){ + public TaggedItem() { this(Item::new); } - public TaggedItem(Function itemSupplierIn){ + public TaggedItem(Function itemSupplierIn) { this.itemSupplier = itemSupplierIn; } diff --git a/src/main/java/com/simibubi/create/AllSpecialTextures.java b/src/main/java/com/simibubi/create/AllSpecialTextures.java index 67aa34421..e8a3f15fa 100644 --- a/src/main/java/com/simibubi/create/AllSpecialTextures.java +++ b/src/main/java/com/simibubi/create/AllSpecialTextures.java @@ -8,6 +8,7 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @EventBusSubscriber(value = Dist.CLIENT) public enum AllSpecialTextures { + BLANK("blank.png"), SELECTION("selection.png"), ; diff --git a/src/main/java/com/simibubi/create/ScreenResources.java b/src/main/java/com/simibubi/create/ScreenResources.java index 307b26599..3270590ab 100644 --- a/src/main/java/com/simibubi/create/ScreenResources.java +++ b/src/main/java/com/simibubi/create/ScreenResources.java @@ -41,7 +41,7 @@ public enum ScreenResources { FILTER("filter.png", 200, 100), ATTRIBUTE_FILTER("filter.png", 0, 100, 200, 86), - + SEQUENCER("sequencer.png", 156, 128), SEQUENCER_INSTRUCTION("sequencer.png", 14, 47, 131, 18), SEQUENCER_WAIT("sequencer.png", 14, 65, 131, 18), @@ -79,6 +79,7 @@ public enum ScreenResources { // JEI JEI_SLOT("jei/widgets.png", 18, 18), + JEI_CHANCE_SLOT("jei/widgets.png", 20, 156, 18, 18), JEI_CATALYST_SLOT("jei/widgets.png", 0, 156, 18, 18), JEI_ARROW("jei/widgets.png", 19, 10, 42, 10), JEI_LONG_ARROW("jei/widgets.png", 19, 0, 71, 10), diff --git a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java index 4bbf9f277..ff99bd785 100644 --- a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java +++ b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java @@ -1,7 +1,6 @@ package com.simibubi.create.compat.jei; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import com.google.common.base.Predicate; @@ -28,13 +27,11 @@ import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.components.crafter.MechanicalCraftingRecipe; import com.simibubi.create.modules.contraptions.components.mixer.MixingRecipe; import com.simibubi.create.modules.contraptions.components.press.MechanicalPressTileEntity; -import com.simibubi.create.modules.contraptions.processing.ProcessingOutput; import com.simibubi.create.modules.logistics.block.inventories.FlexcrateScreen; import com.simibubi.create.modules.schematics.block.SchematicannonScreen; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; -import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.registration.IGuiHandlerRegistration; import mezz.jei.api.registration.IRecipeCatalystRegistration; import mezz.jei.api.registration.IRecipeCategoryRegistration; @@ -226,28 +223,4 @@ public class CreateJEI implements IModPlugin { return byType; } - public static void addStochasticTooltip(IGuiItemStackGroup itemStacks, List results) { - itemStacks.addTooltipCallback((slotIndex, input, ingredient, tooltip) -> { - if (input) - return; - ProcessingOutput output = results.get(slotIndex - 1); - if (output.getChance() != 1) - tooltip.add(1, TextFormatting.GOLD - + Lang.translate("recipe.processing.chance", (int) (output.getChance() * 100))); - }); - } - - public static void addCatalystTooltip(IGuiItemStackGroup itemStacks, Map catalystIndices) { - itemStacks.addTooltipCallback((slotIndex, input, ingredient, tooltip) -> { - if (!input) - return; - if (!catalystIndices.containsKey(slotIndex)) - return; - Float chance = catalystIndices.get(slotIndex); - tooltip.add(1, TextFormatting.YELLOW + Lang.translate("recipe.processing.catalyst")); - tooltip.add(2, TextFormatting.GOLD - + Lang.translate("recipe.processing.chanceToReturn", (int) (chance.floatValue() * 100))); - }); - } - } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/BlastingViaFanCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/BlastingViaFanCategory.java index a2970b286..e791f6637 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/BlastingViaFanCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/BlastingViaFanCategory.java @@ -2,38 +2,18 @@ package com.simibubi.create.compat.jei.category; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllItems; -import com.simibubi.create.Create; -import com.simibubi.create.compat.jei.DoubleItemIcon; import com.simibubi.create.foundation.gui.ScreenElementRenderer; -import com.simibubi.create.foundation.utility.Lang; -import mezz.jei.api.gui.drawable.IDrawable; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.FlowingFluidBlock; -import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.item.crafting.AbstractCookingRecipe; -import net.minecraft.util.ResourceLocation; public class BlastingViaFanCategory extends ProcessingViaFanCategory { - private static ResourceLocation ID = new ResourceLocation(Create.ID, "blasting_via_fan"); - private IDrawable icon; - public BlastingViaFanCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllItems.PROPELLER.get()), - () -> new ItemStack(Items.LAVA_BUCKET)); - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("blasting_via_fan", doubleItemIcon(AllItems.PROPELLER.get(), Items.LAVA_BUCKET)); } @Override @@ -41,11 +21,6 @@ public class BlastingViaFanCategory extends ProcessingViaFanCategory { +public class BlockCuttingCategory extends CreateRecipeCategory { - private AnimatedSaw saw; - private static ResourceLocation ID = new ResourceLocation(Create.ID, "block_cutting"); - private IDrawable icon; - private IDrawable background = new EmptyBackground(177, 70); + private AnimatedSaw saw = new AnimatedSaw(); public BlockCuttingCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllBlocks.SAW.get()), - () -> new ItemStack(Items.STONE_BRICK_STAIRS)); - saw = new AnimatedSaw(); - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("block_cutting", doubleItemIcon(AllBlocks.SAW.get(), Items.STONE_BRICK_STAIRS), emptyBackground(177, 70)); } @Override @@ -55,16 +34,6 @@ public class BlockCuttingCategory implements IRecipeCategory { - - private static ResourceLocation ID = new ResourceLocation(Create.ID, "blockzapper_upgrade"); - private IDrawable icon; +public class BlockzapperUpgradeCategory extends CreateRecipeCategory { public BlockzapperUpgradeCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllItems.PLACEMENT_HANDGUN.get()), - () -> ItemStack.EMPTY); // replace with uparrow when available - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("blockzapper_upgrade", itemIcon(AllItems.PLACEMENT_HANDGUN.get()), + new ScreenResourceWrapper(BLOCKZAPPER_UPGRADE_RECIPE)); } @Override @@ -57,16 +38,6 @@ public class BlockzapperUpgradeCategory implements IRecipeCategory> implements IRecipeCategory { + + private ResourceLocation uid; + private String name; + private IDrawable icon; + private IDrawable background; + + public CreateRecipeCategory(String id, IDrawable icon, IDrawable background) { + uid = new ResourceLocation(Create.ID, id); + name = id; + this.background = background; + this.icon = icon; + } + + @Override + public IDrawable getIcon() { + return icon; + } + + @Override + public ResourceLocation getUid() { + return uid; + } + + @Override + public String getTitle() { + return Lang.translate("recipe." + name); + } + + @Override + public IDrawable getBackground() { + return background; + } + + protected static ScreenResources getRenderedSlot(IRecipe recipe, int index) { + ScreenResources jeiSlot = ScreenResources.JEI_SLOT; + if (!(recipe instanceof ProcessingRecipe)) + return jeiSlot; + ProcessingRecipe processingRecipe = (ProcessingRecipe) recipe; + List rollableResults = processingRecipe.getRollableResults(); + if (rollableResults.size() <= index) + return jeiSlot; + if (processingRecipe.getRollableResults().get(index).getChance() == 1) + return jeiSlot; + return ScreenResources.JEI_CHANCE_SLOT; + } + + protected static IDrawable emptyBackground(int width, int height) { + return new EmptyBackground(width, height); + } + + protected static IDrawable doubleItemIcon(IItemProvider item1, IItemProvider item2) { + return new DoubleItemIcon(() -> new ItemStack(item1), () -> new ItemStack(item2)); + } + + protected static IDrawable itemIcon(IItemProvider item) { + return new DoubleItemIcon(() -> new ItemStack(item), () -> ItemStack.EMPTY); + } + + protected static void addStochasticTooltip(IGuiItemStackGroup itemStacks, List results) { + itemStacks.addTooltipCallback((slotIndex, input, ingredient, tooltip) -> { + if (input) + return; + ProcessingOutput output = results.get(slotIndex - 1); + if (output.getChance() != 1) + tooltip.add(1, TextFormatting.GOLD + + Lang.translate("recipe.processing.chance", (int) (output.getChance() * 100))); + }); + } + + protected static void addCatalystTooltip(IGuiItemStackGroup itemStacks, Map catalystIndices) { + itemStacks.addTooltipCallback((slotIndex, input, ingredient, tooltip) -> { + if (!input) + return; + if (!catalystIndices.containsKey(slotIndex)) + return; + Float chance = catalystIndices.get(slotIndex); + tooltip.add(1, TextFormatting.YELLOW + Lang.translate("recipe.processing.catalyst")); + tooltip.add(2, TextFormatting.GOLD + + Lang.translate("recipe.processing.chanceToReturn", (int) (chance.floatValue() * 100))); + }); + } + +} diff --git a/src/main/java/com/simibubi/create/compat/jei/category/CrushingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/CrushingCategory.java index 2b4bdc07a..0b2fb2238 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/CrushingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/CrushingCategory.java @@ -5,45 +5,23 @@ import java.util.List; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; -import com.simibubi.create.Create; import com.simibubi.create.ScreenResources; -import com.simibubi.create.compat.jei.CreateJEI; -import com.simibubi.create.compat.jei.DoubleItemIcon; -import com.simibubi.create.compat.jei.EmptyBackground; import com.simibubi.create.compat.jei.category.animations.AnimatedCrushingWheels; -import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.components.crusher.AbstractCrushingRecipe; import com.simibubi.create.modules.contraptions.processing.ProcessingOutput; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -public class CrushingCategory implements IRecipeCategory { +public class CrushingCategory extends CreateRecipeCategory { - private static ResourceLocation ID = new ResourceLocation(Create.ID, "crushing"); private AnimatedCrushingWheels crushingWheels = new AnimatedCrushingWheels(); - private IDrawable icon; - private IDrawable background = new EmptyBackground(177, 100); public CrushingCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllBlocks.CRUSHING_WHEEL.get()), - () -> new ItemStack(AllItems.CRUSHED_GOLD.get())); - } - - @Override - public IDrawable getBackground() { - return background; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("crushing", doubleItemIcon(AllBlocks.CRUSHING_WHEEL.get(), AllItems.CRUSHED_GOLD.get()), + emptyBackground(177, 100)); } @Override @@ -51,16 +29,6 @@ public class CrushingCategory implements IRecipeCategory return AbstractCrushingRecipe.class; } - @Override - public String getTitle() { - return Lang.translate("recipe.crushing"); - } - - @Override - public IDrawable getIcon() { - return icon; - } - @Override public void setIngredients(AbstractCrushingRecipe recipe, IIngredients ingredients) { ingredients.setInputIngredients(recipe.getIngredients()); @@ -81,7 +49,7 @@ public class CrushingCategory implements IRecipeCategory itemStacks.set(outputIndex + 1, results.get(outputIndex).getStack()); } - CreateJEI.addStochasticTooltip(itemStacks, results); + addStochasticTooltip(itemStacks, results); } @Override @@ -93,7 +61,7 @@ public class CrushingCategory implements IRecipeCategory int size = results.size(); int offset = -size * 19 / 2; for (int outputIndex = 0; outputIndex < results.size(); outputIndex++) - ScreenResources.JEI_SLOT.draw(getBackground().getWidth() / 2 + offset + 19 * outputIndex, 78); + getRenderedSlot(recipe, outputIndex).draw(getBackground().getWidth() / 2 + offset + 19 * outputIndex, 78); crushingWheels.draw(92, 49); } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/MechanicalCraftingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/MechanicalCraftingCategory.java index 9ee140650..9d6406833 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/MechanicalCraftingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/MechanicalCraftingCategory.java @@ -3,65 +3,39 @@ package com.simibubi.create.compat.jei.category; import java.util.Arrays; import com.simibubi.create.AllBlocks; -import com.simibubi.create.Create; import com.simibubi.create.ScreenResources; -import com.simibubi.create.compat.jei.DoubleItemIcon; -import com.simibubi.create.compat.jei.EmptyBackground; import com.simibubi.create.compat.jei.category.animations.AnimatedCrafter; import com.simibubi.create.foundation.utility.Lang; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; -import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.ShapedRecipe; import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -public class MechanicalCraftingCategory implements IRecipeCategory { +public class MechanicalCraftingCategory extends CreateRecipeCategory { private AnimatedCrafter crafter; - private ResourceLocation id; - private IDrawable icon; - private IDrawable background; private boolean large; public MechanicalCraftingCategory(boolean large) { + super("mechanical_crafting" + (large ? "_large" : ""), itemIcon(AllBlocks.MECHANICAL_CRAFTER.get()), + emptyBackground(large ? 177 : 177, large ? 235 : 81)); this.large = large; - icon = new DoubleItemIcon(() -> new ItemStack(AllBlocks.MECHANICAL_CRAFTER.get()), () -> ItemStack.EMPTY); crafter = new AnimatedCrafter(large); - id = new ResourceLocation(Create.ID, "mechanical_crafting" + (large ? "_large" : "")); - background = new EmptyBackground(large ? 177 : 177, large ? 235 : 81); } public static boolean isSmall(ShapedRecipe recipe) { return Math.max((recipe).getWidth(), (recipe).getHeight()) <= 4; } - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return id; - } - @Override public String getTitle() { return Lang.translate("recipe.mechanical_crafting"); } - @Override - public IDrawable getBackground() { - return background; - } - @Override public void setIngredients(ShapedRecipe recipe, IIngredients ingredients) { ingredients.setInputIngredients(recipe.getIngredients()); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/MillingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/MillingCategory.java index 25a555411..86e0b9b23 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/MillingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/MillingCategory.java @@ -5,45 +5,22 @@ import java.util.List; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; -import com.simibubi.create.Create; import com.simibubi.create.ScreenResources; -import com.simibubi.create.compat.jei.CreateJEI; -import com.simibubi.create.compat.jei.DoubleItemIcon; -import com.simibubi.create.compat.jei.EmptyBackground; import com.simibubi.create.compat.jei.category.animations.AnimatedMillstone; -import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.components.crusher.AbstractCrushingRecipe; import com.simibubi.create.modules.contraptions.processing.ProcessingOutput; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -public class MillingCategory implements IRecipeCategory { +public class MillingCategory extends CreateRecipeCategory { - private static ResourceLocation ID = new ResourceLocation(Create.ID, "milling"); private AnimatedMillstone millstone = new AnimatedMillstone(); - private IDrawable icon; - private IDrawable background = new EmptyBackground(177, 53); public MillingCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllBlocks.MILLSTONE.get()), - () -> new ItemStack(AllItems.FLOUR.get())); - } - - @Override - public IDrawable getBackground() { - return background; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("milling", doubleItemIcon(AllBlocks.MILLSTONE.get(), AllItems.FLOUR.get()), emptyBackground(177, 53)); } @Override @@ -51,16 +28,6 @@ public class MillingCategory implements IRecipeCategory return AbstractCrushingRecipe.class; } - @Override - public String getTitle() { - return Lang.translate("recipe.milling"); - } - - @Override - public IDrawable getIcon() { - return icon; - } - @Override public void setIngredients(AbstractCrushingRecipe recipe, IIngredients ingredients) { ingredients.setInputIngredients(recipe.getIngredients()); @@ -83,7 +50,7 @@ public class MillingCategory implements IRecipeCategory itemStacks.set(outputIndex + 1, results.get(outputIndex).getStack()); } - CreateJEI.addStochasticTooltip(itemStacks, results); + addStochasticTooltip(itemStacks, results); } @Override @@ -95,17 +62,19 @@ public class MillingCategory implements IRecipeCategory ScreenResources.JEI_ARROW.draw(85, 32); ScreenResources.JEI_DOWN_ARROW.draw(43, 4); - if (size > 1) { - for (int i = 0; i < size; i++) { - int xOffset = i % 2 == 0 ? 0 : 19; - int yOffset = (i / 2) * -19; - ScreenResources.JEI_SLOT.draw(133 + xOffset, 27 + yOffset); - } - } else { - ScreenResources.JEI_SLOT.draw(139, 27); + millstone.draw(57, 27); + + if (size == 1) { + getRenderedSlot(recipe, 0).draw(139, 27); + return; + } + + for (int i = 0; i < size; i++) { + int xOffset = i % 2 == 0 ? 0 : 19; + int yOffset = (i / 2) * -19; + getRenderedSlot(recipe, i).draw(133 + xOffset, 27 + yOffset); } - millstone.draw(57, 27); } } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/MixingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/MixingCategory.java index 00342dcb7..65e165a19 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/MixingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/MixingCategory.java @@ -10,59 +10,32 @@ import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.AllBlocks; -import com.simibubi.create.Create; import com.simibubi.create.ScreenResources; -import com.simibubi.create.compat.jei.CreateJEI; -import com.simibubi.create.compat.jei.DoubleItemIcon; -import com.simibubi.create.compat.jei.EmptyBackground; import com.simibubi.create.compat.jei.category.animations.AnimatedMixer; import com.simibubi.create.foundation.item.ItemHelper; -import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.components.mixer.MixingRecipe; import com.simibubi.create.modules.contraptions.processing.ProcessingIngredient; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -public class MixingCategory implements IRecipeCategory { +public class MixingCategory extends CreateRecipeCategory { - private AnimatedMixer mixer; - private static ResourceLocation ID = new ResourceLocation(Create.ID, "mixing"); - private IDrawable icon; - private IDrawable background = new EmptyBackground(177, 70); + private AnimatedMixer mixer = new AnimatedMixer(); public MixingCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllBlocks.MECHANICAL_MIXER.get()), - () -> new ItemStack(AllBlocks.BASIN.get())); - mixer = new AnimatedMixer(); + super("mixing", doubleItemIcon(AllBlocks.MECHANICAL_MIXER.get(), AllBlocks.BASIN.get()), + emptyBackground(177, 70)); } @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; - } - - @Override - public String getTitle() { - return Lang.translate("recipe.mixing"); - } - - @Override - public IDrawable getBackground() { - return background; + public Class getRecipeClass() { + return MixingRecipe.class; } @Override @@ -77,7 +50,7 @@ public class MixingCategory implements IRecipeCategory { NonNullList recipeIngredients = recipe.getIngredients(); List> actualIngredients = ItemHelper.condenseIngredients(recipeIngredients); - + Map catalystIndices = new HashMap<>(9); for (int i = 0; i < actualIngredients.size(); i++) { for (ProcessingIngredient processingIngredient : recipe.getRollableIngredients()) { @@ -107,13 +80,11 @@ public class MixingCategory implements IRecipeCategory { itemStacks.init(i, false, 141, 50); itemStacks.set(i, recipe.getRecipeOutput().getStack()); - CreateJEI.addCatalystTooltip(itemStacks, catalystIndices); + addCatalystTooltip(itemStacks, catalystIndices); } @Override public void draw(MixingRecipe recipe, double mouseX, double mouseY) { - // this might actually be pretty bad with big ingredients. ^ its a draw method - List> actualIngredients = ItemHelper.condenseIngredients(recipe.getIngredients()); int size = actualIngredients.size(); @@ -135,9 +106,4 @@ public class MixingCategory implements IRecipeCategory { mixer.draw(getBackground().getWidth() / 2 + 20, 8); } - @Override - public Class getRecipeClass() { - return MixingRecipe.class; - } - } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/MysteriousItemConversionCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/MysteriousItemConversionCategory.java index 85277b79f..5dca137a5 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/MysteriousItemConversionCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/MysteriousItemConversionCategory.java @@ -5,29 +5,16 @@ import java.util.Arrays; import java.util.List; import com.simibubi.create.AllItems; -import com.simibubi.create.Create; import com.simibubi.create.ScreenResources; import com.simibubi.create.compat.jei.ConversionRecipe; -import com.simibubi.create.compat.jei.CreateJEI; -import com.simibubi.create.compat.jei.DoubleItemIcon; -import com.simibubi.create.compat.jei.EmptyBackground; -import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.processing.ProcessingOutput; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -public class MysteriousItemConversionCategory implements IRecipeCategory { - - private static ResourceLocation ID = new ResourceLocation(Create.ID, "mystery_conversion"); - private IDrawable icon; - private IDrawable background = new EmptyBackground(177, 50); +public class MysteriousItemConversionCategory extends CreateRecipeCategory { public static List getRecipes() { List recipes = new ArrayList<>(); @@ -37,17 +24,7 @@ public class MysteriousItemConversionCategory implements IRecipeCategory AllItems.CHROMATIC_COMPOUND.asStack(), () -> ItemStack.EMPTY); - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("mystery_conversion", itemIcon(AllItems.CHROMATIC_COMPOUND.get()), emptyBackground(177, 50)); } @Override @@ -55,16 +32,6 @@ public class MysteriousItemConversionCategory implements IRecipeCategory results = recipe.getRollableResults(); - itemStacks.init(0, true, 26, 16); itemStacks.set(0, Arrays.asList(recipe.getIngredients().get(0).getMatchingStacks())); itemStacks.init(1, false, 131, 16); itemStacks.set(1, results.get(0).getStack()); - - CreateJEI.addStochasticTooltip(itemStacks, results); } @Override diff --git a/src/main/java/com/simibubi/create/compat/jei/category/PackingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/PackingCategory.java index c7c0f7bad..90b1d180f 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/PackingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/PackingCategory.java @@ -3,47 +3,25 @@ package com.simibubi.create.compat.jei.category; import java.util.Arrays; import com.simibubi.create.AllBlocks; -import com.simibubi.create.Create; import com.simibubi.create.ScreenResources; -import com.simibubi.create.compat.jei.DoubleItemIcon; -import com.simibubi.create.compat.jei.EmptyBackground; import com.simibubi.create.compat.jei.category.animations.AnimatedPress; -import com.simibubi.create.foundation.utility.Lang; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; -import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.ICraftingRecipe; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -public class PackingCategory implements IRecipeCategory> { +public class PackingCategory extends CreateRecipeCategory> { - private AnimatedPress press; - private static ResourceLocation ID = new ResourceLocation(Create.ID, "packing"); - private IDrawable icon; - private IDrawable background = new EmptyBackground(177, 70); + private AnimatedPress press = new AnimatedPress(true); public PackingCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllBlocks.MECHANICAL_PRESS.get()), - () -> new ItemStack(AllBlocks.BASIN.get())); - press = new AnimatedPress(true); - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("packing", doubleItemIcon(AllBlocks.MECHANICAL_PRESS.get(), AllBlocks.BASIN.get()), + emptyBackground(177, 70)); } @Override @@ -51,16 +29,6 @@ public class PackingCategory implements IRecipeCategory> { return ICraftingRecipe.class; } - @Override - public String getTitle() { - return Lang.translate("recipe.packing"); - } - - @Override - public IDrawable getBackground() { - return background; - } - @Override public void setIngredients(IRecipe recipe, IIngredients ingredients) { ingredients.setInputIngredients(recipe.getIngredients()); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java index a12209cb7..fa1834570 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/PolishingCategory.java @@ -5,66 +5,35 @@ import java.util.List; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllItems; -import com.simibubi.create.Create; import com.simibubi.create.ScreenResources; -import com.simibubi.create.compat.jei.CreateJEI; -import com.simibubi.create.compat.jei.DoubleItemIcon; -import com.simibubi.create.compat.jei.EmptyBackground; -import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.processing.ProcessingOutput; import com.simibubi.create.modules.curiosities.tools.SandPaperPolishingRecipe; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -public class PolishingCategory implements IRecipeCategory { +public class PolishingCategory extends CreateRecipeCategory { - private static ResourceLocation ID = new ResourceLocation(Create.ID, "sandpaper_polishing"); - private IDrawable icon; - private IDrawable background = new EmptyBackground(177, 55); private ItemStack renderedSandpaper; public PolishingCategory() { - icon = new DoubleItemIcon(() -> AllItems.SAND_PAPER.asStack(), () -> ItemStack.EMPTY); + super("sandpaper_polishing", itemIcon(AllItems.SAND_PAPER.get()), emptyBackground(177, 55)); renderedSandpaper = AllItems.SAND_PAPER.asStack(); } - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; - } - @Override public Class getRecipeClass() { return SandPaperPolishingRecipe.class; } - @Override - public String getTitle() { - return Lang.translate("recipe.sandpaper_polishing"); - } - - @Override - public IDrawable getBackground() { - return background; - } - @Override public void setIngredients(SandPaperPolishingRecipe recipe, IIngredients ingredients) { ingredients.setInputIngredients(recipe.getIngredients()); @@ -81,13 +50,13 @@ public class PolishingCategory implements IRecipeCategory { +public class PressingCategory extends CreateRecipeCategory { - private AnimatedPress press; - private static ResourceLocation ID = new ResourceLocation(Create.ID, "pressing"); - private IDrawable icon; - private IDrawable background = new EmptyBackground(177, 70); + private AnimatedPress press = new AnimatedPress(false); public PressingCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllBlocks.MECHANICAL_PRESS.get()), - () -> new ItemStack(AllItems.IRON_SHEET.get())); - press = new AnimatedPress(false); - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("pressing", doubleItemIcon(AllBlocks.MECHANICAL_PRESS.get(), AllItems.IRON_SHEET.get()), + emptyBackground(177, 70)); } @Override @@ -52,16 +29,6 @@ public class PressingCategory implements IRecipeCategory { return PressingRecipe.class; } - @Override - public String getTitle() { - return Lang.translate("recipe.pressing"); - } - - @Override - public IDrawable getBackground() { - return background; - } - @Override public void setIngredients(PressingRecipe recipe, IIngredients ingredients) { ingredients.setInputIngredients(recipe.getIngredients()); @@ -79,16 +46,16 @@ public class PressingCategory implements IRecipeCategory { itemStacks.init(outputIndex + 1, false, 131 + 19 * outputIndex, 50); itemStacks.set(outputIndex + 1, results.get(outputIndex).getStack()); } - - CreateJEI.addStochasticTooltip(itemStacks, results); + + addStochasticTooltip(itemStacks, results); } @Override public void draw(PressingRecipe recipe, double mouseX, double mouseY) { ScreenResources.JEI_SLOT.draw(26, 50); - ScreenResources.JEI_SLOT.draw(131, 50); + getRenderedSlot(recipe, 0).draw(131, 50); if (recipe.getRollableResults().size() > 1) - ScreenResources.JEI_SLOT.draw(131 + 19, 50); + getRenderedSlot(recipe, 1).draw(131 + 19, 50); ScreenResources.JEI_SHADOW.draw(61, 41); ScreenResources.JEI_LONG_ARROW.draw(52, 54); press.draw(getBackground().getWidth() / 2, 8); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java index cd3d0ff7c..4ac5715d5 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java @@ -6,7 +6,6 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.ScreenResources; -import com.simibubi.create.compat.jei.EmptyBackground; import com.simibubi.create.compat.jei.category.animations.AnimatedKinetics; import com.simibubi.create.foundation.gui.ScreenElementRenderer; @@ -15,22 +14,18 @@ import mezz.jei.api.gui.IRecipeLayout; import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.item.crafting.IRecipe; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; -public abstract class ProcessingViaFanCategory> implements IRecipeCategory { +public abstract class ProcessingViaFanCategory> extends CreateRecipeCategory { - private IDrawable background = new EmptyBackground(177, 70); - - @Override - public IDrawable getBackground() { - return background; + public ProcessingViaFanCategory(String name, IDrawable icon) { + super(name, icon, emptyBackground(177, 70)); } - + @Override public void setIngredients(T recipe, IIngredients ingredients) { ingredients.setInputIngredients(recipe.getIngredients()); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java index 7a42a14ae..b0a17e4c2 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java @@ -4,46 +4,23 @@ import java.util.Arrays; import java.util.List; import com.simibubi.create.AllBlocks; -import com.simibubi.create.Create; import com.simibubi.create.ScreenResources; -import com.simibubi.create.compat.jei.CreateJEI; -import com.simibubi.create.compat.jei.DoubleItemIcon; -import com.simibubi.create.compat.jei.EmptyBackground; import com.simibubi.create.compat.jei.category.animations.AnimatedSaw; -import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.components.saw.CuttingRecipe; import com.simibubi.create.modules.contraptions.processing.ProcessingOutput; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; -import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.util.ResourceLocation; -public class SawingCategory implements IRecipeCategory { +public class SawingCategory extends CreateRecipeCategory { - private AnimatedSaw saw; - private static ResourceLocation ID = new ResourceLocation(Create.ID, "sawing"); - private IDrawable icon; - private IDrawable background = new EmptyBackground(177, 70); + private AnimatedSaw saw = new AnimatedSaw(); public SawingCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllBlocks.SAW.get()), () -> new ItemStack(Items.OAK_LOG)); - saw = new AnimatedSaw(); - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("sawing", doubleItemIcon(AllBlocks.SAW.get(), Items.OAK_LOG), emptyBackground(177, 70)); } @Override @@ -51,16 +28,6 @@ public class SawingCategory implements IRecipeCategory { return CuttingRecipe.class; } - @Override - public String getTitle() { - return Lang.translate("recipe.sawing"); - } - - @Override - public IDrawable getBackground() { - return background; - } - @Override public void setIngredients(CuttingRecipe recipe, IIngredients ingredients) { ingredients.setInputIngredients(recipe.getIngredients()); @@ -81,8 +48,8 @@ public class SawingCategory implements IRecipeCategory { itemStacks.init(outputIndex + 1, false, 117 + xOffset, 47 + yOffset); itemStacks.set(outputIndex + 1, results.get(outputIndex).getStack()); } - - CreateJEI.addStochasticTooltip(itemStacks, results); + + addStochasticTooltip(itemStacks, results); } @Override @@ -92,7 +59,7 @@ public class SawingCategory implements IRecipeCategory { for (int i = 0; i < size; i++) { int xOffset = i % 2 == 0 ? 0 : 19; int yOffset = (i / 2) * -19; - ScreenResources.JEI_SLOT.draw(117 + xOffset, 47 + yOffset); + getRenderedSlot(recipe, i).draw(117 + xOffset, 47 + yOffset); } ScreenResources.JEI_DOWN_ARROW.draw(70, 6); ScreenResources.JEI_SHADOW.draw(58, 55); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/SmokingViaFanCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/SmokingViaFanCategory.java index 1444881d9..1ddd16611 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/SmokingViaFanCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/SmokingViaFanCategory.java @@ -1,36 +1,16 @@ package com.simibubi.create.compat.jei.category; import com.simibubi.create.AllItems; -import com.simibubi.create.Create; -import com.simibubi.create.compat.jei.DoubleItemIcon; import com.simibubi.create.foundation.gui.ScreenElementRenderer; -import com.simibubi.create.foundation.utility.Lang; -import mezz.jei.api.gui.drawable.IDrawable; import net.minecraft.block.Blocks; -import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.item.crafting.SmokingRecipe; -import net.minecraft.util.ResourceLocation; public class SmokingViaFanCategory extends ProcessingViaFanCategory { - private static ResourceLocation ID = new ResourceLocation(Create.ID, "smoking_via_fan"); - private IDrawable icon; - public SmokingViaFanCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllItems.PROPELLER.get()), - () -> new ItemStack(Items.BLAZE_POWDER)); - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("smoking_via_fan", doubleItemIcon(AllItems.PROPELLER.get(), Items.BLAZE_POWDER)); } @Override @@ -38,11 +18,6 @@ public class SmokingViaFanCategory extends ProcessingViaFanCategory Blocks.FIRE.getDefaultState()); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/SplashingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/SplashingCategory.java index fbf53fac5..df073ecc4 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/SplashingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/SplashingCategory.java @@ -5,52 +5,24 @@ import java.util.List; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllItems; -import com.simibubi.create.Create; import com.simibubi.create.ScreenResources; -import com.simibubi.create.compat.jei.CreateJEI; -import com.simibubi.create.compat.jei.DoubleItemIcon; -import com.simibubi.create.compat.jei.EmptyBackground; import com.simibubi.create.foundation.gui.ScreenElementRenderer; -import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.components.fan.SplashingRecipe; import com.simibubi.create.modules.contraptions.processing.ProcessingOutput; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.ingredients.IIngredients; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.FlowingFluidBlock; -import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.util.ResourceLocation; public class SplashingCategory extends ProcessingViaFanCategory { - private static ResourceLocation ID = new ResourceLocation(Create.ID, "splashing"); - private IDrawable icon; - private IDrawable background = new EmptyBackground(177, 70); - public SplashingCategory() { - icon = new DoubleItemIcon(() -> new ItemStack(AllItems.PROPELLER.get()), - () -> new ItemStack(Items.WATER_BUCKET)); - } - - @Override - public IDrawable getBackground() { - return background; - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public ResourceLocation getUid() { - return ID; + super("splashing", doubleItemIcon(AllItems.PROPELLER.get(), Items.WATER_BUCKET)); } @Override @@ -58,11 +30,6 @@ public class SplashingCategory extends ProcessingViaFanCategory return SplashingRecipe.class; } - @Override - public String getTitle() { - return Lang.translate("recipe.splashing"); - } - @Override public void setIngredients(SplashingRecipe recipe, IIngredients ingredients) { ingredients.setInputIngredients(recipe.getIngredients()); @@ -85,7 +52,7 @@ public class SplashingCategory extends ProcessingViaFanCategory itemStacks.set(outputIndex + 1, results.get(outputIndex).getStack()); } - CreateJEI.addStochasticTooltip(itemStacks, results); + addStochasticTooltip(itemStacks, results); } @Override @@ -97,14 +64,15 @@ public class SplashingCategory extends ProcessingViaFanCategory ScreenResources.JEI_SHADOW.draw(66, 39); ScreenResources.JEI_LONG_ARROW.draw(53, 51); - if (size > 1) { - for (int i = 0; i < size; i++) { - int xOffset = i % 2 == 0 ? 0 : 19; - int yOffset = (i / 2) * -19; - ScreenResources.JEI_SLOT.draw(133 + xOffset, 47 + yOffset); - } - } else { - ScreenResources.JEI_SLOT.draw(139, 47); + if (size == 1) { + getRenderedSlot(recipe, 0).draw(139, 47); + return; + } + + for (int i = 0; i < size; i++) { + int xOffset = i % 2 == 0 ? 0 : 19; + int yOffset = (i / 2) * -19; + getRenderedSlot(recipe, i).draw(133 + xOffset, 47 + yOffset); } } diff --git a/src/main/java/com/simibubi/create/foundation/behaviour/base/PosBoundSmartTileEntity.java b/src/main/java/com/simibubi/create/foundation/behaviour/base/PosBoundSmartTileEntity.java new file mode 100644 index 000000000..4bd838015 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/behaviour/base/PosBoundSmartTileEntity.java @@ -0,0 +1,59 @@ +package com.simibubi.create.foundation.behaviour.base; + +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.math.BlockPos; + +public abstract class PosBoundSmartTileEntity extends SmartTileEntity { + + private boolean newPositionVisited; + + public PosBoundSmartTileEntity(TileEntityType tileEntityTypeIn) { + super(tileEntityTypeIn); + newPositionVisited = true; + } + + @Override + public void initialize() { + if (!world.isRemote && newPositionVisited) { + newPositionVisited = false; + initInNewPosition(); + } + super.initialize(); + } + + @Override + public void read(CompoundNBT compound) { + long positionInTag = new BlockPos(compound.getInt("x"), compound.getInt("y"), compound.getInt("z")).toLong(); + long positionKey = compound.getLong("BoundPosition"); + + newPositionVisited = false; + if (!hasWorld() || !world.isRemote) { + if (positionInTag != positionKey) { + removePositionDependentData(compound); + newPositionVisited = true; + } + } + + super.read(compound); + } + + /** + * Server-only. When this TE realizes, that it's reading its tag in a different + * position, it should remove all position dependent information here. + * + * @param nbt + */ + protected void removePositionDependentData(CompoundNBT nbt) { + + } + + /** + * Server-only. When a TE has been created or moved, it will call this before the + * regular init. + */ + protected void initInNewPosition() { + + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/behaviour/base/SmartTileEntity.java b/src/main/java/com/simibubi/create/foundation/behaviour/base/SmartTileEntity.java index fd761ff30..5ce414b0e 100644 --- a/src/main/java/com/simibubi/create/foundation/behaviour/base/SmartTileEntity.java +++ b/src/main/java/com/simibubi/create/foundation/behaviour/base/SmartTileEntity.java @@ -86,8 +86,9 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements ITicka list.forEach(b -> behaviours.put(b.getType(), b)); } - forEachBehaviour(tb -> tb.readNBT(compound)); super.read(compound); + forEachBehaviour(tb -> tb.readNBT(compound)); + if (world != null && world.isRemote) updateClient(compound); } @@ -106,7 +107,7 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements ITicka public void lazyTick() { } - + protected void forEachBehaviour(Consumer action) { behaviours.values().forEach(tb -> { if (!tb.isPaused()) diff --git a/src/main/java/com/simibubi/create/foundation/behaviour/filtering/FilteringBehaviour.java b/src/main/java/com/simibubi/create/foundation/behaviour/filtering/FilteringBehaviour.java index 82fa386e5..901ff7c8e 100644 --- a/src/main/java/com/simibubi/create/foundation/behaviour/filtering/FilteringBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/behaviour/filtering/FilteringBehaviour.java @@ -39,8 +39,7 @@ public class FilteringBehaviour extends TileEntityBehaviour { filter = ItemStack.EMPTY; slotPositioning = slot; showCount = false; - callback = stack -> { - }; + callback = stack -> {}; textShift = Vec3d.ZERO; count = 0; ticksUntilScrollPacket = -1; @@ -114,11 +113,7 @@ public class FilteringBehaviour extends TileEntityBehaviour { public void setFilter(ItemStack stack) { filter = stack.copy(); callback.accept(filter); - - if (filter.getItem() instanceof FilterItem) - count = 0; - else - count = stack.getCount(); + count = (filter.getItem() instanceof FilterItem) ? 0 : Math.min(stack.getCount(), stack.getMaxStackSize()); forceClientState = true; tileEntity.markDirty(); diff --git a/src/main/java/com/simibubi/create/foundation/behaviour/filtering/FilteringHandler.java b/src/main/java/com/simibubi/create/foundation/behaviour/filtering/FilteringHandler.java index 1fa219809..215f5355e 100644 --- a/src/main/java/com/simibubi/create/foundation/behaviour/filtering/FilteringHandler.java +++ b/src/main/java/com/simibubi/create/foundation/behaviour/filtering/FilteringHandler.java @@ -87,12 +87,14 @@ public class FilteringHandler { return false; if (!filtering.testHit(objectMouseOver.getHitVec())) return false; - if (filtering.getFilter().isEmpty()) + ItemStack filterItem = filtering.getFilter(); + if (filterItem.isEmpty()) return false; filtering.ticksUntilScrollPacket = 10; - filtering.scrollableValue = (int) MathHelper - .clamp(filtering.scrollableValue + delta * (AllKeys.ctrlDown() ? 16 : 1), 0, 64); + int maxAmount = (filterItem.getItem() instanceof FilterItem) ? 64 : filterItem.getMaxStackSize(); + filtering.scrollableValue = + (int) MathHelper.clamp(filtering.scrollableValue + delta * (AllKeys.ctrlDown() ? 16 : 1), 0, maxAmount); return true; } diff --git a/src/main/java/com/simibubi/create/foundation/behaviour/linked/LinkBehaviour.java b/src/main/java/com/simibubi/create/foundation/behaviour/linked/LinkBehaviour.java index 1a3310a6c..10677554e 100644 --- a/src/main/java/com/simibubi/create/foundation/behaviour/linked/LinkBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/behaviour/linked/LinkBehaviour.java @@ -34,6 +34,7 @@ public class LinkBehaviour extends TileEntityBehaviour { ValueBoxTransform secondSlot; Vec3d textShift; + public boolean newPosition; private Mode mode; private Supplier transmission; private Consumer signalCallback; @@ -45,6 +46,7 @@ public class LinkBehaviour extends TileEntityBehaviour { firstSlot = slots.getLeft(); secondSlot = slots.getRight(); textShift = Vec3d.ZERO; + newPosition = true; } public static LinkBehaviour receiver(SmartTileEntity te, Pair slots, @@ -84,6 +86,8 @@ public class LinkBehaviour extends TileEntityBehaviour { } public void updateReceiver(boolean networkPowered) { + if (!newPosition) + return; signalCallback.accept(networkPowered); } @@ -97,6 +101,7 @@ public class LinkBehaviour extends TileEntityBehaviour { if (tileEntity.getWorld().isRemote) return; getHandler().addToNetwork(this); + newPosition = true; } public Pair getNetworkKey() { @@ -116,10 +121,15 @@ public class LinkBehaviour extends TileEntityBehaviour { super.writeNBT(compound); compound.put("FrequencyFirst", frequencyFirst.getStack().write(new CompoundNBT())); compound.put("FrequencyLast", frequencyLast.getStack().write(new CompoundNBT())); + compound.putLong("LastKnownPosition", tileEntity.getPos().toLong()); } @Override public void readNBT(CompoundNBT compound) { + long positionInTag = tileEntity.getPos().toLong(); + long positionKey = compound.getLong("LastKnownPosition"); + newPosition = positionInTag != positionKey; + super.readNBT(compound); frequencyFirst = new Frequency(ItemStack.read(compound.getCompound("FrequencyFirst"))); frequencyLast = new Frequency(ItemStack.read(compound.getCompound("FrequencyLast"))); diff --git a/src/main/java/com/simibubi/create/foundation/behaviour/scrollvalue/ScrollValueRenderer.java b/src/main/java/com/simibubi/create/foundation/behaviour/scrollvalue/ScrollValueRenderer.java index 35b4263af..212634da5 100644 --- a/src/main/java/com/simibubi/create/foundation/behaviour/scrollvalue/ScrollValueRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/behaviour/scrollvalue/ScrollValueRenderer.java @@ -61,6 +61,8 @@ public class ScrollValueRenderer { } else render(world, pos, face, behaviour, highlight); TessellatorHelper.cleanUpAfterDrawing(); + GlStateManager.enableAlphaTest(); + GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); } protected static void render(ClientWorld world, BlockPos pos, Direction face, ScrollValueBehaviour behaviour, diff --git a/src/main/java/com/simibubi/create/foundation/utility/TessellatorHelper.java b/src/main/java/com/simibubi/create/foundation/utility/TessellatorHelper.java index 904c55da3..724452f80 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/TessellatorHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/TessellatorHelper.java @@ -23,7 +23,6 @@ public class TessellatorHelper { GlStateManager.pushMatrix(); GlStateManager.pushLightingAttributes(); GlStateManager.enableBlend(); - GlStateManager.enableAlphaTest(); GlStateManager.color4f(1, 1, 1, 1); ActiveRenderInfo renderInfo = mc.gameRenderer.getActiveRenderInfo(); @@ -45,7 +44,7 @@ public class TessellatorHelper { GlStateManager.color3f(1, 1, 1); } - + public static void fightZFighting(int id) { long randomBits = (long) id * 493286711L; randomBits = randomBits * randomBits * 4392167121L + randomBits * 98761L; @@ -68,10 +67,10 @@ public class TessellatorHelper { } public static void cleanUpAfterDrawing() { - GlStateManager.disableAlphaTest(); - GlStateManager.disableBlend(); GlStateManager.popAttributes(); GlStateManager.popMatrix(); + GlStateManager.disableAlphaTest(); + GlStateManager.disableBlend(); } public static void drawString(String str, float x, float y, float z, boolean scalesUp, boolean hasDepth) { diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/AABBOutline.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/AABBOutline.java new file mode 100644 index 000000000..da9ab87dd --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/AABBOutline.java @@ -0,0 +1,55 @@ +package com.simibubi.create.foundation.utility.outliner; + +import com.simibubi.create.AllSpecialTextures; +import com.simibubi.create.foundation.utility.ColorHelper; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; + +public class AABBOutline extends Outline { + + private AxisAlignedBB bb = new AxisAlignedBB(new BlockPos(25, 70, 90)).expand(0, 1, 0); + + @Override + public void render(BufferBuilder buffer) { + begin(); + + Vec3d color = ColorHelper.getRGB(0xFFFFFF); + float alpha = 1f; + + AllSpecialTextures.BLANK.bind(); + Vec3d xyz = new Vec3d(bb.minX, bb.minY, bb.minZ); + Vec3d Xyz = new Vec3d(bb.maxX, bb.minY, bb.minZ); + Vec3d xYz = new Vec3d(bb.minX, bb.maxY, bb.minZ); + Vec3d XYz = new Vec3d(bb.maxX, bb.maxY, bb.minZ); + Vec3d xyZ = new Vec3d(bb.minX, bb.minY, bb.maxZ); + Vec3d XyZ = new Vec3d(bb.maxX, bb.minY, bb.maxZ); + Vec3d xYZ = new Vec3d(bb.minX, bb.maxY, bb.maxZ); + Vec3d XYZ = new Vec3d(bb.maxX, bb.maxY, bb.maxZ); + + Vec3d start = xyz; + renderAACuboidLine(start, Xyz, color, alpha, buffer); + renderAACuboidLine(start, xYz, color, alpha, buffer); + renderAACuboidLine(start, xyZ, color, alpha, buffer); + + start = XyZ; + renderAACuboidLine(start, xyZ, color, alpha, buffer); + renderAACuboidLine(start, XYZ, color, alpha, buffer); + renderAACuboidLine(start, Xyz, color, alpha, buffer); + + start = XYz; + renderAACuboidLine(start, xYz, color, alpha, buffer); + renderAACuboidLine(start, Xyz, color, alpha, buffer); + renderAACuboidLine(start, XYZ, color, alpha, buffer); + + start = xYZ; + renderAACuboidLine(start, XYZ, color, alpha, buffer); + renderAACuboidLine(start, xyZ, color, alpha, buffer); + renderAACuboidLine(start, xYz, color, alpha, buffer); + + draw(); + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/BlockClusterOutline.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/BlockClusterOutline.java new file mode 100644 index 000000000..131a24c10 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/BlockClusterOutline.java @@ -0,0 +1,143 @@ +package com.simibubi.create.foundation.utility.outliner; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import com.simibubi.create.AllSpecialTextures; +import com.simibubi.create.foundation.utility.ColorHelper; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.util.Direction; +import net.minecraft.util.Direction.Axis; +import net.minecraft.util.Direction.AxisDirection; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; + +public class BlockClusterOutline extends Outline { + + private Cluster cluster; + private float alpha; + + public BlockClusterOutline(Iterable selection) { + cluster = new Cluster(); + selection.forEach(cluster::include); + alpha = .5f; + } + + @Override + public void render(BufferBuilder buffer) { + begin(); + Vec3d color = ColorHelper.getRGB(0xDDDDDD); + AllSpecialTextures.SELECTION.bind(); + + for (MergeEntry face : cluster.visibleFaces.keySet()) { + AxisDirection axisDirection = cluster.visibleFaces.get(face); + Direction direction = Direction.getFacingFromAxis(axisDirection, face.axis); + BlockPos pos = face.pos; + if (axisDirection == AxisDirection.POSITIVE) + pos = pos.offset(direction.getOpposite()); + renderFace(pos, direction, color, alpha * .25f, 1 / 64d, buffer); + } + + flush(); + AllSpecialTextures.BLANK.bind(); + + for (MergeEntry edge : cluster.visibleEdges) { + lineWidth = 1 / 16f * alpha; + Vec3d start = new Vec3d(edge.pos); + Direction direction = Direction.getFacingFromAxis(AxisDirection.POSITIVE, edge.axis); + renderAACuboidLine(start, new Vec3d(edge.pos.offset(direction)), color, 1, buffer); + } + + draw(); + } + + public void setAlpha(float alpha) { + this.alpha = alpha; + } + + private static class Cluster { + + Map visibleFaces; + Set visibleEdges; + + public Cluster() { + visibleEdges = new HashSet<>(); + visibleFaces = new HashMap<>(); + } + + public void include(BlockPos pos) { + + // 6 FACES + for (Axis axis : Axis.values()) { + Direction direction = Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis); + for (int offset : new int[] { 0, 1 }) { + MergeEntry entry = new MergeEntry(axis, pos.offset(direction, offset)); + if (visibleFaces.remove(entry) == null) + visibleFaces.put(entry, offset == 0 ? AxisDirection.NEGATIVE : AxisDirection.POSITIVE); + } + } + + // 12 EDGES + for (Axis axis : Axis.values()) { + for (Axis axis2 : Axis.values()) { + if (axis == axis2) + continue; + for (Axis axis3 : Axis.values()) { + if (axis == axis3) + continue; + if (axis2 == axis3) + continue; + + Direction direction = Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis2); + Direction direction2 = Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis3); + + for (int offset : new int[] { 0, 1 }) { + BlockPos entryPos = pos.offset(direction, offset); + for (int offset2 : new int[] { 0, 1 }) { + entryPos = entryPos.offset(direction2, offset2); + MergeEntry entry = new MergeEntry(axis, entryPos); + if (!visibleEdges.remove(entry)) + visibleEdges.add(entry); + } + } + } + + break; + } + } + + } + + } + + private static class MergeEntry { + + Axis axis; + BlockPos pos; + + public MergeEntry(Axis axis, BlockPos pos) { + this.axis = axis; + this.pos = pos; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof MergeEntry)) + return false; + + MergeEntry other = (MergeEntry) o; + return this.axis == other.axis && this.pos.equals(other.pos); + } + + @Override + public int hashCode() { + return this.pos.hashCode() * 31 + axis.ordinal(); + } + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java new file mode 100644 index 000000000..a0fe1646e --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java @@ -0,0 +1,109 @@ +package com.simibubi.create.foundation.utility.outliner; + +import org.lwjgl.opengl.GL11; + +import com.simibubi.create.foundation.utility.VecHelper; + +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.Direction; +import net.minecraft.util.Direction.Axis; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; + +public abstract class Outline { + + protected float lineWidth = 1 / 32f; + + public abstract void render(BufferBuilder buffer); + + protected void begin() { + BufferBuilder buffer = Tessellator.getInstance().getBuffer(); + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP); + } + + protected void draw() { + Tessellator.getInstance().draw(); + } + + protected void flush() { + draw(); + begin(); + } + + protected void renderAACuboidLine(Vec3d start, Vec3d end, Vec3d rgb, float alpha, BufferBuilder buffer) { + Vec3d diff = end.subtract(start); + if (diff.x + diff.y + diff.z < 0) { + Vec3d temp = start; + start = end; + end = temp; + diff = diff.scale(-1); + } + + Vec3d extension = diff.normalize().scale(lineWidth / 2); + Vec3d plane = VecHelper.planeByNormal(diff); + Axis axis = Direction.getFacingFromVector(diff.x, diff.y, diff.z).getAxis(); + + start = start.subtract(extension); + end = end.add(extension); + plane = plane.scale(lineWidth / 2); + Vec3d a1 = plane.add(start); + Vec3d b1 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vec3d a2 = plane.add(start); + Vec3d b2 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vec3d a3 = plane.add(start); + Vec3d b3 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vec3d a4 = plane.add(start); + Vec3d b4 = plane.add(end); + + putQuad(b4, b3, b2, b1, rgb, alpha, buffer); + putQuad(a1, a2, a3, a4, rgb, alpha, buffer); + + putQuad(a1, b1, b2, a2, rgb, alpha, buffer); + putQuad(a2, b2, b3, a3, rgb, alpha, buffer); + putQuad(a3, b3, b4, a4, rgb, alpha, buffer); + putQuad(a4, b4, b1, a1, rgb, alpha, buffer); + } + + protected void renderFace(BlockPos pos, Direction face, Vec3d rgb, float alpha, double scaleOffset, + BufferBuilder buffer) { + Vec3d center = VecHelper.getCenterOf(pos); + Vec3d offset = new Vec3d(face.getDirectionVec()); + Vec3d plane = VecHelper.planeByNormal(offset); + Axis axis = face.getAxis(); + + offset = offset.scale(1 / 2f + scaleOffset); + plane = plane.scale(1 / 2f).add(offset); + + int deg = face.getAxisDirection().getOffset() * 90; + Vec3d a1 = plane.add(center); + plane = VecHelper.rotate(plane, deg, axis); + Vec3d a2 = plane.add(center); + plane = VecHelper.rotate(plane, deg, axis); + Vec3d a3 = plane.add(center); + plane = VecHelper.rotate(plane, deg, axis); + Vec3d a4 = plane.add(center); + + putQuad(a1, a2, a3, a4, rgb, alpha, buffer); + } + + protected void putQuad(Vec3d v1, Vec3d v2, Vec3d v3, Vec3d v4, Vec3d rgb, float alpha, BufferBuilder buffer) { + putVertex(v1, rgb, 0, 0, alpha, buffer); + putVertex(v2, rgb, 1, 0, alpha, buffer); + putVertex(v3, rgb, 1, 1, alpha, buffer); + putVertex(v4, rgb, 0, 1, alpha, buffer); + } + + protected void putVertex(Vec3d pos, Vec3d rgb, float u, float v, float alpha, BufferBuilder buffer) { + int i = 15 << 20 | 15 << 4; + int j = i >> 16 & '\uffff'; + int k = i & '\uffff'; + buffer.pos(pos.x, pos.y, pos.z).tex(u, v).color((float) rgb.x, (float) rgb.y, (float) rgb.z, alpha) + .lightmap(j, k).endVertex(); + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/OutlineParticle.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/OutlineParticle.java new file mode 100644 index 000000000..80feeb1ca --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/OutlineParticle.java @@ -0,0 +1,58 @@ +package com.simibubi.create.foundation.utility.outliner; + +import com.mojang.blaze3d.platform.GlStateManager; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.player.ClientPlayerEntity; +import net.minecraft.client.particle.IParticleRenderType; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class OutlineParticle extends Particle { + + private Outline outline; + + private OutlineParticle(Outline outline, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn) { + super(worldIn, xCoordIn, yCoordIn, zCoordIn); + this.outline = outline; + this.maxAge = 1024; + } + + public static OutlineParticle create(Outline outline) { + Minecraft mc = Minecraft.getInstance(); + ClientPlayerEntity player = mc.player; + OutlineParticle effect = new OutlineParticle(outline, mc.world, player.posX, player.posY, player.posZ); + mc.particles.addEffect(effect); + return effect; + } + + public void remove() { + isExpired = true; + } + + @Override + public void renderParticle(BufferBuilder buffer, ActiveRenderInfo entityIn, float partialTicks, float rotationX, + float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) { + GlStateManager.pushMatrix(); + Vec3d view = entityIn.getProjectedView(); + GlStateManager.translated(-view.x, -view.y, -view.z); + GlStateManager.depthMask(false); + GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + + GlStateManager.enableBlend(); + outline.render(buffer); + GlStateManager.disableBlend(); + + GlStateManager.depthMask(true); + GlStateManager.popMatrix(); + } + + @Override + public IParticleRenderType getRenderType() { + return IParticleRenderType.CUSTOM; + } + +} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java index 45eaa4939..d70185a9a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java @@ -1,7 +1,6 @@ package com.simibubi.create.modules.contraptions.base; import com.simibubi.create.foundation.item.ItemDescription.Palette; -import com.simibubi.create.modules.contraptions.RotationPropagator; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -47,7 +46,10 @@ public abstract class KineticBlock extends Block implements IRotate { return tool == ToolType.AXE || tool == ToolType.PICKAXE; } - // IRotate + @Override + public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) { + // onBlockAdded is useless for init, as sometimes the TE gets re-instantiated + } @Override public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) { @@ -64,8 +66,6 @@ public abstract class KineticBlock extends Block implements IRotate { return null; } - // Block - @Override public boolean hasTileEntity(BlockState state) { return true; @@ -79,8 +79,8 @@ public abstract class KineticBlock extends Block implements IRotate { @Override public abstract TileEntity createTileEntity(BlockState state, IBlockReader world); - @SuppressWarnings("deprecation") @Override + @SuppressWarnings("deprecation") public void updateNeighbors(BlockState stateIn, IWorld worldIn, BlockPos pos, int flags) { super.updateNeighbors(stateIn, worldIn, pos, flags); if (worldIn.isRemote()) @@ -90,8 +90,11 @@ public abstract class KineticBlock extends Block implements IRotate { if (!(tileEntity instanceof KineticTileEntity)) return; + // Remove previous information when block is added KineticTileEntity kte = (KineticTileEntity) tileEntity; - RotationPropagator.handleAdded(worldIn.getWorld(), pos, kte); + kte.warnOfMovement(); + kte.clearKineticInformation(); + kte.updateSpeed = true; } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java index de3df92b2..21b8f0e60 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java @@ -41,12 +41,14 @@ public abstract class KineticTileEntity extends SmartTileEntity public @Nullable Long network; public @Nullable BlockPos source; public boolean networkDirty; + public boolean updateSpeed; protected KineticEffectHandler effects; protected float speed; protected float capacity; protected float stress; protected boolean overStressed; + protected boolean wasMoved; private int flickerTally; private int networkSize; @@ -57,6 +59,7 @@ public abstract class KineticTileEntity extends SmartTileEntity public KineticTileEntity(TileEntityType typeIn) { super(typeIn); effects = new KineticEffectHandler(this); + updateSpeed = true; } @Override @@ -73,6 +76,9 @@ public abstract class KineticTileEntity extends SmartTileEntity @Override public void tick() { + if (!world.isRemote && needsSpeedUpdate()) + attachKinetics(); + super.tick(); effects.tick(); @@ -179,6 +185,9 @@ public abstract class KineticTileEntity extends SmartTileEntity public CompoundNBT write(CompoundNBT compound) { compound.putFloat("Speed", speed); + if (needsSpeedUpdate()) + compound.putBoolean("NeedsSpeedUpdate", true); + if (hasSource()) compound.put("Source", NBTUtil.writeBlockPos(source)); @@ -188,7 +197,7 @@ public abstract class KineticTileEntity extends SmartTileEntity networkTag.putFloat("Stress", stress); networkTag.putFloat("Capacity", capacity); networkTag.putInt("Size", networkSize); - + if (lastStressApplied != 0) networkTag.putFloat("AddedStress", lastStressApplied); if (lastCapacityProvided != 0) @@ -200,16 +209,21 @@ public abstract class KineticTileEntity extends SmartTileEntity return super.write(compound); } + public boolean needsSpeedUpdate() { + return updateSpeed; + } + @Override public void read(CompoundNBT compound) { + clearKineticInformation(); + + // DO NOT READ kinetic information when placed after movement + if (wasMoved) { + super.read(compound); + return; + } + speed = compound.getFloat("Speed"); - source = null; - network = null; - overStressed = false; - stress = 0; - capacity = 0; - lastStressApplied = 0; - lastCapacityProvided = 0; if (compound.contains("Source")) source = NBTUtil.readBlockPos(compound.getCompound("Source")); @@ -313,6 +327,7 @@ public abstract class KineticTileEntity extends SmartTileEntity } public void attachKinetics() { + updateSpeed = false; RotationPropagator.handleAdded(world, pos, this); } @@ -414,6 +429,21 @@ public abstract class KineticTileEntity extends SmartTileEntity } + public void clearKineticInformation() { + speed = 0; + source = null; + network = null; + overStressed = false; + stress = 0; + capacity = 0; + lastStressApplied = 0; + lastCapacityProvided = 0; + } + + public void warnOfMovement() { + wasMoved = true; + } + public int getFlickerScore() { return flickerTally; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java index 844833d8c..21ea16106 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java @@ -12,6 +12,8 @@ import com.simibubi.create.modules.contraptions.components.contraptions.piston.M import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonBlock.PistonState; import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock; import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyTileEntity; +import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock.MagnetBlock; +import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock.RopeBlock; import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock; import com.simibubi.create.modules.logistics.block.RedstoneLinkBlock; import com.simibubi.create.modules.logistics.block.extractor.ExtractorBlock; @@ -82,7 +84,7 @@ public class BlockMovementTraits { if (block instanceof PulleyBlock) { TileEntity te = world.getTileEntity(pos); if (te instanceof PulleyTileEntity) - return !((PulleyTileEntity) te).running && ((PulleyTileEntity) te).offset == 0; + return !((PulleyTileEntity) te).running; } if (AllBlocks.BELT.typeOf(blockState)) @@ -126,6 +128,10 @@ public class BlockMovementTraits { return true; if (block instanceof RedstoneLinkBlock) return true; + if (block instanceof RopeBlock) + return true; + if (block instanceof MagnetBlock) + return true; return false; } @@ -187,6 +193,8 @@ public class BlockMovementTraits { return state.get(PortableStorageInterfaceBlock.FACING) == facing; if (AllBlocks.HARVESTER.typeOf(state)) return state.get(BlockStateProperties.HORIZONTAL_FACING) == facing; + if (AllBlocks.ROPE_PULLEY.typeOf(state)) + return facing == Direction.DOWN; return isBrittle(state); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ChassisRangeDisplay.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ChassisRangeDisplay.java index b8a1b2e42..6714c05fc 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ChassisRangeDisplay.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ChassisRangeDisplay.java @@ -13,10 +13,11 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.AllItems; import com.simibubi.create.AllKeys; import com.simibubi.create.foundation.utility.TessellatorHelper; +import com.simibubi.create.foundation.utility.outliner.BlockClusterOutline; +import com.simibubi.create.foundation.utility.outliner.OutlineParticle; import com.simibubi.create.modules.contraptions.components.contraptions.chassis.ChassisTileEntity; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; @@ -30,13 +31,15 @@ public class ChassisRangeDisplay { private static GroupEntry lastHoveredGroup = null; private static class Entry { - Set includedPositions; + BlockClusterOutline outline; + OutlineParticle particle; ChassisTileEntity te; int timer; public Entry(ChassisTileEntity te) { this.te = te; - includedPositions = createSelection(te); + outline = new BlockClusterOutline(createSelection(te)); + particle = OutlineParticle.create(outline); timer = DISPLAY_TIME; } @@ -80,14 +83,19 @@ public class ChassisRangeDisplay { World world = Minecraft.getInstance().world; boolean hasWrench = AllItems.WRENCH.typeOf(player.getHeldItemMainhand()); - for (Iterator iterator = entries.keySet().iterator(); iterator.hasNext();) - if (tickEntry(entries.get(iterator.next()), hasWrench)) + for (Iterator iterator = entries.keySet().iterator(); iterator.hasNext();) { + Entry entry = entries.get(iterator.next()); + if (tickEntry(entry, hasWrench)) { + entry.particle.remove(); iterator.remove(); + } + } for (Iterator iterator = groupEntries.iterator(); iterator.hasNext();) { GroupEntry group = iterator.next(); if (tickEntry(group, hasWrench)) { iterator.remove(); + group.particle.remove(); if (group == lastHoveredGroup) lastHoveredGroup = null; } @@ -113,8 +121,11 @@ public class ChassisRangeDisplay { if (ctrl) { GroupEntry existingGroupForPos = getExistingGroupForPos(pos); if (existingGroupForPos != null) { - for (ChassisTileEntity included : existingGroupForPos.includedTEs) - entries.remove(included.getPos()); + for (ChassisTileEntity included : existingGroupForPos.includedTEs) { + Entry removed = entries.remove(included.getPos()); + if (removed != null) + removed.particle.remove(); + } existingGroupForPos.timer = DISPLAY_TIME; return; } @@ -162,13 +173,19 @@ public class ChassisRangeDisplay { public static void display(ChassisTileEntity chassis) { deselect(); if (AllKeys.ctrlDown()) { + groupEntries.forEach(e -> e.particle.remove()); groupEntries.clear(); GroupEntry hoveredGroup = new GroupEntry(chassis); - for (ChassisTileEntity included : hoveredGroup.includedTEs) - entries.remove(included.getPos()); + for (ChassisTileEntity included : hoveredGroup.includedTEs) { + Entry remove = entries.remove(included.getPos()); + if (remove != null) + remove.particle.remove(); + } groupEntries.add(hoveredGroup); } else { - entries.put(chassis.getPos(), new Entry(chassis)); + Entry old = entries.put(chassis.getPos(), new Entry(chassis)); + if (old != null) + old.particle.remove(); } } @@ -190,17 +207,23 @@ public class ChassisRangeDisplay { } public static void renderPositions(Entry entry, float partialTicks) { - TessellatorHelper.begin(); - BlockPos size = new BlockPos(1, 1, 1); +// GlStateManager.pushMatrix(); +// RenderHelper.disableStandardItemLighting(); +// GlStateManager.normal3f(0.0F, 1.0F, 0.0F); +// GlStateManager.color4f(1, 1, 1, 1); +// GlStateManager.enableTexture(); +// GlStateManager.depthMask(false); +// GlStateManager.enableBlend(); +// GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); +// float timer = entry.timer - partialTicks; - float alpha = timer > 20 ? .5f : timer / 40f; - GlStateManager.color4f(1, .7f, 0, alpha); - Set includedPositions = entry.includedPositions; - GlStateManager.depthMask(false); - for (BlockPos pos : includedPositions) - TessellatorHelper.cube(Tessellator.getInstance().getBuffer(), pos, size, 1 / 16f - 1 / 64f, true, false); - TessellatorHelper.draw(); - GlStateManager.depthMask(true); + float alpha = timer > 20 ? 1 : timer / 20f; + entry.outline.setAlpha(alpha); +// entry.outline.render(Tessellator.getInstance().getBuffer()); +// +// GlStateManager.disableBlend(); +// GlStateManager.depthMask(true); +// GlStateManager.popMatrix(); } private static GroupEntry getExistingGroupForPos(BlockPos pos) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java index c4c0a9033..a272f87c0 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/Contraption.java @@ -26,13 +26,16 @@ import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.components.contraptions.chassis.AbstractChassisBlock; import com.simibubi.create.modules.contraptions.components.contraptions.chassis.ChassisTileEntity; import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonBlock; -import com.simibubi.create.modules.contraptions.components.contraptions.piston.PistonPoleBlock; import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonBlock.PistonState; import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonHeadBlock; +import com.simibubi.create.modules.contraptions.components.contraptions.piston.PistonPoleBlock; +import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock; +import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyTileEntity; +import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock.MagnetBlock; +import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock.RopeBlock; import com.simibubi.create.modules.contraptions.components.saw.SawBlock; import com.simibubi.create.modules.contraptions.redstone.ContactBlock; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock; -import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity; import com.simibubi.create.modules.logistics.block.inventories.FlexcrateBlock; import net.minecraft.block.AbstractButtonBlock; @@ -53,6 +56,7 @@ import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.AxisDirection; +import net.minecraft.util.Rotation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -117,7 +121,8 @@ public abstract class Contraption { if (bounds == null) bounds = new AxisAlignedBB(BlockPos.ZERO); - frontier.add(pos); + if (!BlockMovementTraits.isBrittle(world.getBlockState(pos))) + frontier.add(pos); if (!addToInitialFrontier(world, pos, forcedDirection, frontier)) return false; for (int limit = 100000; limit > 0; limit--) { @@ -147,6 +152,8 @@ public abstract class Contraption { if (!world.isBlockPresent(pos)) return false; + if (isAnchoringBlockAt(pos)) + return true; if (!BlockMovementTraits.movementNecessary(world, pos)) return true; if (!BlockMovementTraits.movementAllowed(world, pos)) @@ -154,6 +161,7 @@ public abstract class Contraption { BlockState state = world.getBlockState(pos); if (isChassis(state) && !moveChassis(world, pos, forcedDirection, frontier, visited)) return false; + if (AllBlocks.FLEXCRATE.typeOf(state)) FlexcrateBlock.splitCrate(world, pos); if (AllBlocks.BELT.typeOf(state)) { @@ -164,7 +172,27 @@ public abstract class Contraption { if (prevPos != null && !visited.contains(prevPos)) frontier.add(prevPos); } - + + // Pulleys drag their rope and their attached structure + if (state.getBlock() instanceof PulleyBlock) { + int limit = AllConfigs.SERVER.kinetics.maxRopeLength.get(); + BlockPos ropePos = pos; + while (limit-- >= 0) { + ropePos = ropePos.down(); + if (!world.isBlockPresent(ropePos)) + break; + BlockState ropeState = world.getBlockState(ropePos); + Block block = ropeState.getBlock(); + if (!(block instanceof RopeBlock) && !(block instanceof MagnetBlock)) { + if (!visited.contains(ropePos)) + frontier.add(ropePos); + break; + } + add(ropePos, capture(world, ropePos)); + } + } + + // Pistons drag their attaches poles and extension if (state.getBlock() instanceof MechanicalPistonBlock) { int limit = AllConfigs.SERVER.kinetics.maxPistonPoles.get(); Direction direction = state.get(MechanicalPistonBlock.FACING); @@ -188,7 +216,7 @@ public abstract class Contraption { if (limit <= -1) return false; } - + BlockPos searchPos = pos; while (limit-- >= 0) { searchPos = searchPos.offset(direction.getOpposite()); @@ -202,17 +230,19 @@ public abstract class Contraption { } break; } - + if (limit <= -1) return false; } - + + // Doors try to stay whole if (state.getBlock() instanceof DoorBlock) { BlockPos otherPartPos = pos.up(state.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER ? 1 : -1); if (!visited.contains(otherPartPos)) frontier.add(otherPartPos); } + // Slime blocks drag adjacent blocks if possible boolean isSlimeBlock = state.getBlock() instanceof SlimeBlock; for (Direction offset : Direction.values()) { BlockPos offsetPos = pos.offset(offset); @@ -224,14 +254,15 @@ public abstract class Contraption { return false; continue; } - if (!visited.contains(offsetPos) - && (isSlimeBlock || BlockMovementTraits.isBlockAttachedTowards(blockState, offset.getOpposite()))) + if (!visited.contains(offsetPos) && ((isSlimeBlock && !BlockMovementTraits.isBrittle(blockState)) + || BlockMovementTraits.isBlockAttachedTowards(blockState, offset.getOpposite()))) frontier.add(offsetPos); } add(pos, capture(world, pos)); if (blocks.size() > AllConfigs.SERVER.kinetics.maxBlocksMoved.get()) return false; + return true; } @@ -497,8 +528,16 @@ public abstract class Contraption { && !blockState.getCollisionShape(world, targetPos).isEmpty()) continue; - world.destroyBlock(targetPos, blockState.getCollisionShape(world, targetPos).isEmpty()); + world.destroyBlock(targetPos, true); world.setBlockState(targetPos, state, 3 | BlockFlags.IS_MOVING); + + boolean verticalRotation = transform.rotationAxis == null || transform.rotationAxis.isHorizontal(); + verticalRotation = verticalRotation && transform.rotation != Rotation.NONE; + if (verticalRotation) { + if (state.getBlock() instanceof RopeBlock || state.getBlock() instanceof MagnetBlock) + world.destroyBlock(targetPos, true); + } + TileEntity tileEntity = world.getTileEntity(targetPos); CompoundNBT tag = block.nbt; if (tileEntity != null && tag != null) { @@ -506,22 +545,13 @@ public abstract class Contraption { tag.putInt("y", targetPos.getY()); tag.putInt("z", targetPos.getZ()); - if (tileEntity instanceof BeltTileEntity) { - tag.remove("Length"); - tag.remove("Index"); - tag.putBoolean("DontClearAttachments", true); + if (verticalRotation && tileEntity instanceof PulleyTileEntity) { + tag.remove("Offset"); + tag.remove("InitialOffset"); } tileEntity.read(tag); - if (tileEntity instanceof KineticTileEntity) { - KineticTileEntity kineticTileEntity = (KineticTileEntity) tileEntity; - kineticTileEntity.source = null; - kineticTileEntity.setSpeed(0); - kineticTileEntity.network = null; - kineticTileEntity.attachKinetics(); - } - if (storage.containsKey(block.pos)) { MountedStorage mountedStorage = storage.get(block.pos); if (mountedStorage.isWorking()) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionEntity.java index c4a347028..bf2655afc 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionEntity.java @@ -432,7 +432,7 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD } remove(); } - + @Override protected void doWaterSplashEffect() { } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingContraption.java index e7d3edc64..d32d89010 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingContraption.java @@ -36,6 +36,11 @@ public class BearingContraption extends Contraption { return construct; } + @Override + protected boolean isAnchoringBlockAt(BlockPos pos) { + return pos.equals(anchor.offset(facing.getOpposite())); + } + @Override public void add(BlockPos pos, Pair capture) { BlockPos localPos = pos.subtract(anchor); @@ -62,7 +67,7 @@ public class BearingContraption extends Contraption { public int getSailBlocks() { return sailBlocks; } - + public Direction getFacing() { return facing; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingTileEntity.java index b8d4fd577..1f73f7449 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkBearingTileEntity.java @@ -148,6 +148,9 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe } public void assemble() { + if (!(world.getBlockState(pos).getBlock() instanceof ClockworkBearingBlock)) + return; + Direction direction = getBlockState().get(BlockStateProperties.FACING); // Collect Construct @@ -182,7 +185,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe } public void disassemble() { - if (!running) + if (!running && hourHand == null && minuteHand == null) return; hourAngle = 0; @@ -205,7 +208,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe public void attach(ContraptionEntity contraption) { if (!(contraption.getContraption() instanceof ClockworkContraption)) return; - + ClockworkContraption cc = (ClockworkContraption) contraption.getContraption(); markDirty(); Direction facing = getBlockState().get(BlockStateProperties.FACING); @@ -217,8 +220,10 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe this.minuteHand = contraption; minuteHand.setPosition(anchor.getX(), anchor.getY(), anchor.getZ()); } - if (!world.isRemote) + if (!world.isRemote) { + this.running = true; sendData(); + } } @Override @@ -302,5 +307,5 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe public boolean isRunning() { return running; } - + } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkContraption.java index 25d4687ee..e31759ed6 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/ClockworkContraption.java @@ -32,6 +32,11 @@ public class ClockworkContraption extends Contraption { ignoreBlocks.add(anchor.add(blockPos)); } + @Override + protected boolean isAnchoringBlockAt(BlockPos pos) { + return pos.equals(anchor.offset(facing.getOpposite(), offset + 1)); + } + public static Pair assembleClockworkAt(World world, BlockPos pos, Direction direction) { if (isFrozen()) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingTileEntity.java index d962824b6..bffbbc4e5 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/MechanicalBearingTileEntity.java @@ -150,6 +150,9 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp } public void assemble() { + if (!(world.getBlockState(pos).getBlock() instanceof MechanicalBearingBlock)) + return; + Direction direction = getBlockState().get(FACING); // Collect Construct @@ -161,6 +164,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp if (contraption.blocks.isEmpty()) return; contraption.removeBlocksFromWorld(world, BlockPos.ZERO); + movedContraption = ContraptionEntity.createStationary(world, contraption).controlledBy(this); BlockPos anchor = pos.offset(direction); movedContraption.setPosition(anchor.getX(), anchor.getY(), anchor.getZ()); @@ -172,7 +176,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp sendData(); updateGeneratedRotation(); } - + @Override public void updateGeneratedRotation() { super.updateGeneratedRotation(); @@ -180,7 +184,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp } public void disassemble() { - if (!running) + if (!running && movedContraption == null) return; if (movedContraption != null) movedContraption.disassemble(); @@ -267,8 +271,10 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp markDirty(); BlockPos anchor = pos.offset(blockState.get(FACING)); movedContraption.setPosition(anchor.getX(), anchor.getY(), anchor.getZ()); - if (!world.isRemote) + if (!world.isRemote) { + this.running = true; sendData(); + } } @Override @@ -298,7 +304,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp public boolean isAttachedTo(ContraptionEntity contraption) { return movedContraption == contraption; } - + public boolean isRunning() { return running; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/ChassisTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/ChassisTileEntity.java index d19225985..2cf714806 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/ChassisTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/ChassisTileEntity.java @@ -167,11 +167,7 @@ public class ChassisTileEntity extends SmartTileEntity { // Ignore replaceable Blocks and Air-like if (!BlockMovementTraits.movementNecessary(world, current)) break; - if (AllBlocks.MECHANICAL_PISTON_HEAD.typeOf(currentState)) - break; - if (AllBlocks.MECHANICAL_PISTON.typeOf(currentState)) - break; - if (AllBlocks.STICKY_MECHANICAL_PISTON.typeOf(currentState)) + if (BlockMovementTraits.isBrittle(currentState)) break; positions.add(current); @@ -212,6 +208,8 @@ public class ChassisTileEntity extends SmartTileEntity { continue; if (!BlockMovementTraits.movementNecessary(world, searchPos)) continue; + if (BlockMovementTraits.isBrittle(searchedState)) + continue; localVisited.add(searchPos); if (!searchPos.equals(pos)) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/MountedContraption.java index 1dd193592..610577738 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/MountedContraption.java @@ -8,6 +8,7 @@ import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.AllBlocks; import com.simibubi.create.modules.contraptions.components.contraptions.AllContraptionTypes; +import com.simibubi.create.modules.contraptions.components.contraptions.BlockMovementTraits; import com.simibubi.create.modules.contraptions.components.contraptions.Contraption; import net.minecraft.block.BlockState; @@ -61,8 +62,14 @@ public class MountedContraption extends Contraption { if (!AllBlocks.CART_ASSEMBLER.typeOf(state)) return false; Axis axis = state.get(CartAssemblerBlock.RAIL_SHAPE) == RailShape.EAST_WEST ? Axis.Z : Axis.X; - for (AxisDirection axisDirection : AxisDirection.values()) - frontier.add(pos.offset(Direction.getFacingFromAxis(axisDirection, axis))); + for (AxisDirection axisDirection : AxisDirection.values()) { + Direction facingFromAxis = Direction.getFacingFromAxis(axisDirection, axis); + BlockPos offset = pos.offset(facingFromAxis); + BlockState blockState = world.getBlockState(offset); + if (!BlockMovementTraits.isBrittle(blockState) + || BlockMovementTraits.isBlockAttachedTowards(blockState, facingFromAxis.getOpposite())) + frontier.add(offset); + } return true; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/LinearActuatorTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/LinearActuatorTileEntity.java index 4642683f8..394fd07af 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/LinearActuatorTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/LinearActuatorTileEntity.java @@ -293,8 +293,10 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme @Override public void attach(ContraptionEntity contraption) { this.movedContraption = contraption; - if (!world.isRemote) + if (!world.isRemote) { + this.running = true; sendData(); + } } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonTileEntity.java index 7dda90f67..b71d5cdc2 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/MechanicalPistonTileEntity.java @@ -42,6 +42,9 @@ public class MechanicalPistonTileEntity extends LinearActuatorTileEntity { @Override public void assemble() { + if (!(world.getBlockState(pos).getBlock() instanceof MechanicalPistonBlock)) + return; + Direction direction = getBlockState().get(BlockStateProperties.FACING); // Collect Construct @@ -83,10 +86,11 @@ public class MechanicalPistonTileEntity extends LinearActuatorTileEntity { @Override public void disassemble() { - if (!running) + if (!running && movedContraption == null) return; if (!removed) - getWorld().setBlockState(pos, getBlockState().with(MechanicalPistonBlock.STATE, PistonState.EXTENDED), 3); + getWorld().setBlockState(pos, getBlockState().with(MechanicalPistonBlock.STATE, PistonState.EXTENDED), + 3 | 16); if (movedContraption != null) { applyContraptionPosition(); movedContraption.disassemble(); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonContraption.java index cb2118760..0d115e2e7 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonContraption.java @@ -13,6 +13,7 @@ import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.AllBlocks; import com.simibubi.create.config.AllConfigs; import com.simibubi.create.foundation.utility.NBTHelper; +import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.modules.contraptions.components.contraptions.AllContraptionTypes; import com.simibubi.create.modules.contraptions.components.contraptions.BlockMovementTraits; import com.simibubi.create.modules.contraptions.components.contraptions.Contraption; @@ -63,17 +64,24 @@ public class PistonContraption extends Contraption { BlockPos actualStart = pos; BlockState nextBlock = world.getBlockState(actualStart.offset(direction)); int extensionsInFront = 0; - boolean sticky = STICKY_MECHANICAL_PISTON.typeOf(world.getBlockState(pos)); + BlockState blockState = world.getBlockState(pos); + boolean sticky = STICKY_MECHANICAL_PISTON.typeOf(blockState); - if (world.getBlockState(pos).get(MechanicalPistonBlock.STATE) == PistonState.EXTENDED) { + if (!(blockState.getBlock() instanceof MechanicalPistonBlock)) + return false; + + if (blockState.get(MechanicalPistonBlock.STATE) == PistonState.EXTENDED) { while (PISTON_POLE.typeOf(nextBlock) && nextBlock.get(FACING).getAxis() == direction.getAxis() || MECHANICAL_PISTON_HEAD.typeOf(nextBlock) && nextBlock.get(FACING) == direction) { actualStart = actualStart.offset(direction); poles.add(new BlockInfo(actualStart, nextBlock.with(FACING, direction), null)); extensionsInFront++; - nextBlock = world.getBlockState(actualStart.offset(direction)); + if (MECHANICAL_PISTON_HEAD.typeOf(nextBlock)) + break; + + nextBlock = world.getBlockState(actualStart.offset(direction)); if (extensionsInFront > MechanicalPistonBlock.maxAllowedPistonPoles()) return false; } @@ -122,6 +130,11 @@ public class PistonContraption extends Contraption { return true; } + @Override + protected boolean isAnchoringBlockAt(BlockPos pos) { + return pistonExtensionCollisionBox.contains(VecHelper.getCenterOf(pos.subtract(anchor))); + } + @Override protected boolean addToInitialFrontier(World world, BlockPos pos, Direction direction, List frontier) { frontier.clear(); @@ -138,6 +151,8 @@ public class PistonContraption extends Contraption { if (!BlockMovementTraits.movementNecessary(world, currentPos)) return true; BlockState state = world.getBlockState(currentPos); + if (BlockMovementTraits.isBrittle(state)) + return true; if (AllBlocks.MECHANICAL_PISTON_HEAD.typeOf(state) && state.get(FACING) == direction.getOpposite()) return true; if (!BlockMovementTraits.movementAllowed(world, currentPos)) @@ -146,7 +161,7 @@ public class PistonContraption extends Contraption { if (BlockMovementTraits.notSupportive(state, orientation)) return true; } - return false; // too many + return true; } @Override @@ -165,7 +180,7 @@ public class PistonContraption extends Contraption { return true; if (!AllBlocks.PISTON_POLE.typeOf(state) && pistonState.getBlock() instanceof MechanicalPistonBlock) world.setBlockState(pistonPos, pistonState.with(MechanicalPistonBlock.STATE, PistonState.RETRACTED), - 3); + 3 | 16); return true; } return false; @@ -178,7 +193,7 @@ public class PistonContraption extends Contraption { BlockPos pistonPos = anchor.offset(orientation, -1); BlockState blockState = world.getBlockState(pos); if (pos.equals(pistonPos) && blockState.getBlock() instanceof MechanicalPistonBlock) { - world.setBlockState(pos, blockState.with(MechanicalPistonBlock.STATE, PistonState.MOVING), 66); + world.setBlockState(pos, blockState.with(MechanicalPistonBlock.STATE, PistonState.MOVING), 66 | 16); return true; } return false; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyBlock.java index cfae85eea..eb7303834 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyBlock.java @@ -1,6 +1,5 @@ package com.simibubi.create.modules.contraptions.components.contraptions.pulley; -import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.IHaveNoBlockItem; import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.utility.AllShapes; @@ -9,6 +8,7 @@ import com.simibubi.create.modules.contraptions.base.HorizontalAxisKineticBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.block.material.PushReaction; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.state.EnumProperty; import net.minecraft.state.properties.BlockStateProperties; @@ -41,6 +41,18 @@ public class PulleyBlock extends HorizontalAxisKineticBlock implements ITE anchor.getY() + initialOffset + 1) + return false; + return true; + } + @Override public CompoundNBT writeNBT() { CompoundNBT writeNBT = super.writeNBT(); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyTileEntity.java index d65f0a5f3..a751277d4 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/pulley/PulleyTileEntity.java @@ -37,6 +37,8 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { @Override protected void assemble() { + if (!(world.getBlockState(pos).getBlock() instanceof PulleyBlock)) + return; if (speed == 0) return; if (offset >= getExtensionRange() && getSpeed() > 0) @@ -81,7 +83,7 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { @Override public void disassemble() { - if (!running) + if (!running && movedContraption == null) return; offset = getGridOffset(offset); if (movedContraption != null) @@ -137,6 +139,8 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { BlockPos posBelow = pos.down((int) (offset + getMovementSpeed()) + 1); if (!BlockMovementTraits.movementNecessary(world, posBelow)) return; + if (BlockMovementTraits.isBrittle(world.getBlockState(posBelow))) + return; disassemble(); assembleNextTick = true; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/advanced/sequencer/SequencedGearshiftBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/advanced/sequencer/SequencedGearshiftBlock.java index 1ea746fde..1777303b1 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/advanced/sequencer/SequencedGearshiftBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/advanced/sequencer/SequencedGearshiftBlock.java @@ -87,14 +87,15 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implemen return false; } - if (player instanceof ClientPlayerEntity) - DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> withTileEntityDo(worldIn, pos, this::displayScreen)); + DistExecutor.runWhenOn(Dist.CLIENT, + () -> () -> withTileEntityDo(worldIn, pos, te -> this.displayScreen(te, player))); return true; } @OnlyIn(value = Dist.CLIENT) - protected void displayScreen(SequencedGearshiftTileEntity te) { - ScreenOpener.open(new SequencedGearshiftScreen(te)); + protected void displayScreen(SequencedGearshiftTileEntity te, PlayerEntity player) { + if (player instanceof ClientPlayerEntity) + ScreenOpener.open(new SequencedGearshiftScreen(te)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java index 5b3575587..14127dc93 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java @@ -418,9 +418,9 @@ public class BeltBlock extends HorizontalKineticBlock // Init belts int index = 0; - List beltChain = getBeltChain(world, pos); + List beltChain = getBeltChain(world, currentPos); if (beltChain.size() < 2) { - world.destroyBlock(pos, true); + world.destroyBlock(currentPos, true); return; } @@ -428,7 +428,7 @@ public class BeltBlock extends HorizontalKineticBlock TileEntity tileEntity = world.getTileEntity(beltPos); if (tileEntity instanceof BeltTileEntity) { BeltTileEntity te = (BeltTileEntity) tileEntity; - te.setController(pos); + te.setController(currentPos); te.beltLength = beltChain.size(); te.index = index; te.attachKinetics(); @@ -446,7 +446,7 @@ public class BeltBlock extends HorizontalKineticBlock if (te.isController() && isVertical) te.getInventory().ejectAll(); } else { - world.destroyBlock(pos, true); + world.destroyBlock(currentPos, true); return; } index++; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java index 1842a17d2..18b546483 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java @@ -66,11 +66,6 @@ public class BeltTileEntity extends KineticTileEntity { color = -1; } - @Override - public void initialize() { - super.initialize(); - } - @Override public void tick() { super.tick(); @@ -164,7 +159,9 @@ public class BeltTileEntity extends KineticTileEntity { @Override public CompoundNBT write(CompoundNBT compound) { attachmentTracker.write(compound); - compound.put("Controller", NBTUtil.writeBlockPos(controller)); + + if (controller != null) + compound.put("Controller", NBTUtil.writeBlockPos(controller)); compound.putBoolean("IsController", isController()); compound.putInt("Color", color); compound.putInt("Length", beltLength); @@ -178,21 +175,32 @@ public class BeltTileEntity extends KineticTileEntity { @Override public void read(CompoundNBT compound) { super.read(compound); + if (compound.getBoolean("IsController")) controller = pos; - else - controller = NBTUtil.readBlockPos(compound.getCompound("Controller")); - if (!compound.contains("DontClearAttachments")) + if (!wasMoved) { + if (!isController()) + controller = NBTUtil.readBlockPos(compound.getCompound("Controller")); trackerUpdateTag = compound; - color = compound.getInt("Color"); - beltLength = compound.getInt("Length"); - index = compound.getInt("Index"); + color = compound.getInt("Color"); + beltLength = compound.getInt("Length"); + index = compound.getInt("Index"); + } if (isController()) getInventory().read(compound.getCompound("Inventory")); } + @Override + public void clearKineticInformation() { + super.clearKineticInformation(); + beltLength = 0; + index = 0; + controller = null; + trackerUpdateTag = new CompoundNBT(); + } + public void applyColor(DyeColor colorIn) { int colorValue = colorIn.getMapColor().colorValue; for (BlockPos blockPos : BeltBlock.getBeltChain(world, getController())) { @@ -206,6 +214,8 @@ public class BeltTileEntity extends KineticTileEntity { } public BeltTileEntity getControllerTE() { + if (controller == null) + return null; if (!world.isBlockPresent(controller)) return null; TileEntity te = world.getTileEntity(controller); @@ -219,11 +229,11 @@ public class BeltTileEntity extends KineticTileEntity { } public BlockPos getController() { - return controller; + return controller == null ? pos : controller; } public boolean isController() { - return controller.equals(pos); + return pos.equals(controller); } public float getBeltMovementSpeed() { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/ClutchBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/ClutchBlock.java index 824e5f7dc..07e9a48e8 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/ClutchBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/ClutchBlock.java @@ -1,8 +1,5 @@ package com.simibubi.create.modules.contraptions.relays.encased; -import com.simibubi.create.modules.contraptions.RotationPropagator; -import com.simibubi.create.modules.contraptions.base.KineticTileEntity; - import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; @@ -26,13 +23,7 @@ public class ClutchBlock extends GearshiftBlock { boolean previouslyPowered = state.get(POWERED); if (previouslyPowered != worldIn.isBlockPowered(pos)) { worldIn.setBlockState(pos, state.cycle(POWERED), 2 | 16); - TileEntity te = worldIn.getTileEntity(pos); - if (te == null || !(te instanceof KineticTileEntity)) - return; - if (previouslyPowered) - RotationPropagator.handleAdded(worldIn, pos, (KineticTileEntity) te); - else - RotationPropagator.handleRemoved(worldIn, pos, (KineticTileEntity) te); + detachKinetics(worldIn, pos, previouslyPowered); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/GearshiftBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/GearshiftBlock.java index f9e6eb079..ef370c071 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/GearshiftBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/GearshiftBlock.java @@ -1,7 +1,10 @@ package com.simibubi.create.modules.contraptions.relays.encased; +import java.util.Random; + import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.modules.contraptions.RotationPropagator; +import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.relays.gearbox.GearshiftTileEntity; import net.minecraft.block.Block; @@ -15,6 +18,7 @@ import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorldReader; +import net.minecraft.world.TickPriority; import net.minecraft.world.World; public class GearshiftBlock extends EncasedShaftBlock implements ITE { @@ -51,7 +55,7 @@ public class GearshiftBlock extends EncasedShaftBlock implements ITE RotationPropagator.handleRemoved(worldIn, pos, te)); + detachKinetics(worldIn, pos, true); worldIn.setBlockState(pos, state.cycle(POWERED), 2); } } @@ -65,4 +69,24 @@ public class GearshiftBlock extends EncasedShaftBlock implements ITE () -> withTileEntityDo(worldIn, pos, this::displayScreen)); + DistExecutor.runWhenOn(Dist.CLIENT, + () -> () -> withTileEntityDo(worldIn, pos, te -> this.displayScreen(te, player))); return true; } @OnlyIn(value = Dist.CLIENT) - protected void displayScreen(StockswitchTileEntity te) { - ScreenOpener.open(new StockswitchScreen(te)); + protected void displayScreen(StockswitchTileEntity te, PlayerEntity player) { + if (player instanceof ClientPlayerEntity) + ScreenOpener.open(new StockswitchScreen(te)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateScreen.java b/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateScreen.java index 5ef02e6fe..c699b9737 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateScreen.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateScreen.java @@ -107,6 +107,10 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen= 0) lastModification++; @@ -114,7 +118,7 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen