diff options
Diffstat (limited to 'src/main/java')
3 files changed, 122 insertions, 6 deletions
diff --git a/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java b/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java index e64708d..04cc62a 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java +++ b/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java @@ -85,7 +85,7 @@ public class OhMyVanillaMinecraft implements ModInitializer { configuration = new OmvmConfiguration(defaultConfiguration); } - LOGGER.info("Configuration: \n==========\n" + configuration + "\n=========="); + LOGGER.info(getConfigurationString()); CommandRegistrationCallback.EVENT.register(new CommandRegistrationCallback() { @Override @@ -93,7 +93,7 @@ public class OhMyVanillaMinecraft implements ModInitializer { commandDispatcher.register(CommandManager.literal("omvm").executes(new Command<ServerCommandSource>() { @Override public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { - String text = "OhMyVanillaMinecraft\n==========\n" + getConfiguration() + "\n=========="; + String text = getConfigurationString(); context.getSource().sendFeedback(new LiteralText(text), false); return 1; // 1: success, -1: fail } @@ -131,6 +131,8 @@ public class OhMyVanillaMinecraft implements ModInitializer { @Override public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { try { + boolean previousFixSpamming = configuration.isFixEntityTrackerEntrySpamming(); + String key = context.getArgument("key", String.class); String value = context.getArgument("value", String.class); @@ -170,4 +172,10 @@ public class OhMyVanillaMinecraft implements ModInitializer { } + private String getConfigurationString() { + return "OhMyVanillaMinecraft\n==========\n" + configuration + "\n==========\n" + + "Force enabled tweaks:\n" + "Furnace fuel list lag fix\n" + "=========="; + } + + } diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/AbstractFurnaceBlockEntityMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/AbstractFurnaceBlockEntityMixin.java new file mode 100644 index 0000000..2a95407 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixin/AbstractFurnaceBlockEntityMixin.java @@ -0,0 +1,100 @@ +package com.keuin.ohmyvanillamc.mixin; + +import net.minecraft.block.Blocks; +import net.minecraft.block.entity.AbstractFurnaceBlockEntity; +import net.minecraft.item.Item; +import net.minecraft.item.Items; +import net.minecraft.tag.ItemTags; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.LinkedHashMap; +import java.util.Map; + +@Mixin(AbstractFurnaceBlockEntity.class) +public class AbstractFurnaceBlockEntityMixin { + + private static final Map<Item, Integer> fuelTimeMap = new LinkedHashMap<>(384); // use larger capacity to speed up query and iteration + + static { + + // Copied from 1.16.4 code + // Need change in the future versions + // Hint: replace with regex: + // + // map\.put\(\(Tag\)(.+),.([0-9]+)\)\; + // --replace--> $1.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> map.put(item, $2)); + + fuelTimeMap.put(Items.LAVA_BUCKET.asItem(), 20000); + fuelTimeMap.put(Blocks.COAL_BLOCK.asItem(), 16000); + fuelTimeMap.put(Items.BLAZE_ROD.asItem(), 2400); + fuelTimeMap.put(Items.COAL.asItem(), 1600); + fuelTimeMap.put(Items.CHARCOAL.asItem(), 1600); + ItemTags.LOGS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 300)); + ItemTags.PLANKS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 300)); + ItemTags.WOODEN_STAIRS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 300)); + ItemTags.WOODEN_SLABS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 150)); + ItemTags.WOODEN_TRAPDOORS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 300)); + ItemTags.WOODEN_PRESSURE_PLATES.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 300)); + fuelTimeMap.put(Blocks.OAK_FENCE.asItem(), 300); + fuelTimeMap.put(Blocks.BIRCH_FENCE.asItem(), 300); + fuelTimeMap.put(Blocks.SPRUCE_FENCE.asItem(), 300); + fuelTimeMap.put(Blocks.JUNGLE_FENCE.asItem(), 300); + fuelTimeMap.put(Blocks.DARK_OAK_FENCE.asItem(), 300); + fuelTimeMap.put(Blocks.ACACIA_FENCE.asItem(), 300); + fuelTimeMap.put(Blocks.OAK_FENCE_GATE.asItem(), 300); + fuelTimeMap.put(Blocks.BIRCH_FENCE_GATE.asItem(), 300); + fuelTimeMap.put(Blocks.SPRUCE_FENCE_GATE.asItem(), 300); + fuelTimeMap.put(Blocks.JUNGLE_FENCE_GATE.asItem(), 300); + fuelTimeMap.put(Blocks.DARK_OAK_FENCE_GATE.asItem(), 300); + fuelTimeMap.put(Blocks.ACACIA_FENCE_GATE.asItem(), 300); + fuelTimeMap.put(Blocks.NOTE_BLOCK.asItem(), 300); + fuelTimeMap.put(Blocks.BOOKSHELF.asItem(), 300); + fuelTimeMap.put(Blocks.LECTERN.asItem(), 300); + fuelTimeMap.put(Blocks.JUKEBOX.asItem(), 300); + fuelTimeMap.put(Blocks.CHEST.asItem(), 300); + fuelTimeMap.put(Blocks.TRAPPED_CHEST.asItem(), 300); + fuelTimeMap.put(Blocks.CRAFTING_TABLE.asItem(), 300); + fuelTimeMap.put(Blocks.DAYLIGHT_DETECTOR.asItem(), 300); + ItemTags.BANNERS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 300)); + fuelTimeMap.put(Items.BOW.asItem(), 300); + fuelTimeMap.put(Items.FISHING_ROD.asItem(), 300); + fuelTimeMap.put(Blocks.LADDER.asItem(), 300); + ItemTags.SIGNS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 200)); + fuelTimeMap.put(Items.WOODEN_SHOVEL.asItem(), 200); + fuelTimeMap.put(Items.WOODEN_SWORD.asItem(), 200); + fuelTimeMap.put(Items.WOODEN_HOE.asItem(), 200); + fuelTimeMap.put(Items.WOODEN_AXE.asItem(), 200); + fuelTimeMap.put(Items.WOODEN_PICKAXE.asItem(), 200); + ItemTags.WOODEN_DOORS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 200)); + ItemTags.BOATS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 1200)); + ItemTags.WOOL.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 100)); + ItemTags.WOODEN_BUTTONS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 100)); + fuelTimeMap.put(Items.STICK.asItem(), 100); + ItemTags.SAPLINGS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 100)); + fuelTimeMap.put(Items.BOWL.asItem(), 100); + ItemTags.CARPETS.values().stream().filter(item -> !isNonFlammableWood(item)).forEach(item -> fuelTimeMap.put(item, 67)); + fuelTimeMap.put(Blocks.DRIED_KELP_BLOCK.asItem(), 4001); + fuelTimeMap.put(Items.CROSSBOW.asItem(), 300); + fuelTimeMap.put(Blocks.BAMBOO.asItem(), 50); + fuelTimeMap.put(Blocks.DEAD_BUSH.asItem(), 100); + fuelTimeMap.put(Blocks.SCAFFOLDING.asItem(), 400); + fuelTimeMap.put(Blocks.LOOM.asItem(), 300); + fuelTimeMap.put(Blocks.BARREL.asItem(), 300); + fuelTimeMap.put(Blocks.CARTOGRAPHY_TABLE.asItem(), 300); + fuelTimeMap.put(Blocks.FLETCHING_TABLE.asItem(), 300); + fuelTimeMap.put(Blocks.SMITHING_TABLE.asItem(), 300); + fuelTimeMap.put(Blocks.COMPOSTER.asItem(), 300); + } + + @Invoker("isNonFlammableWood") + private static boolean isNonFlammableWood(Item item) { + throw new AssertionError(); + } + + @Overwrite + public static Map<Item, Integer> createFuelTimeMap() { + return fuelTimeMap; + } +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java index bf1f0b1..faf5c9d 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java +++ b/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java @@ -1,7 +1,6 @@ package com.keuin.ohmyvanillamc.mixin; import com.keuin.ohmyvanillamc.DummyLogger; -import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft; import net.minecraft.server.network.EntityTrackerEntry; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Final; @@ -12,15 +11,24 @@ import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(EntityTrackerEntry.class) public class DisableEntityTrackerEntrySpamming { - private static final Logger DUMMY_LOGGER = new DummyLogger(); + private static final Logger LOGGER_DUMMY = new DummyLogger(); + + static { + setLOGGER(LOGGER_DUMMY); + } @Shadow @Final private static Logger LOGGER; @Accessor("LOGGER") - private static Logger LOGGER() { - return OhMyVanillaMinecraft.getConfiguration().isFixEntityTrackerEntrySpamming() ? DUMMY_LOGGER : LOGGER; + private static Logger getLOGGER() { + throw new AssertionError(); + } + + @Accessor("LOGGER") + private static void setLOGGER(Logger logger) { + throw new AssertionError(); } } |