aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-05-07 20:17:50 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-05-07 20:17:50 +0200
commit22ab4657d65a883b19bbc5613c18c0c4ae195a37 (patch)
tree60c17fef87f23f81a04cd97668aba3245f2735bf /src/main
parent82a1ad7b6a3547f4c305b4459b21e0eadebfc8ad (diff)
downloadparquet-22ab4657d65a883b19bbc5613c18c0c4ae195a37.tar.gz
MC-126244 Hackfix: Cartographer map trade crash
Replaced structure map trade with dummy map around (0,0) to mitigate server crash on large worlds due to poor locateStructure implementation.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/re/jag/parquet/mixin/SellMapFactoryMixin.java49
-rw-r--r--src/main/resources/parquet.mixins.json3
2 files changed, 51 insertions, 1 deletions
diff --git a/src/main/java/re/jag/parquet/mixin/SellMapFactoryMixin.java b/src/main/java/re/jag/parquet/mixin/SellMapFactoryMixin.java
new file mode 100644
index 0000000..7dc536b
--- /dev/null
+++ b/src/main/java/re/jag/parquet/mixin/SellMapFactoryMixin.java
@@ -0,0 +1,49 @@
+package re.jag.parquet.mixin;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.item.FilledMapItem;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.Items;
+import net.minecraft.item.map.MapIcon;
+import net.minecraft.item.map.MapState;
+import net.minecraft.server.world.ServerWorld;
+import net.minecraft.text.LiteralText;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.village.TradeOffer;
+import net.minecraft.village.TradeOffers;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Overwrite;
+import org.spongepowered.asm.mixin.Shadow;
+
+import java.util.Random;
+
+@Mixin(targets="net.minecraft.village.TradeOffers$SellMapFactory")
+public class SellMapFactoryMixin implements TradeOffers.Factory {
+ @Shadow
+ private int price;
+ @Shadow
+ private String structure;
+ @Shadow
+ private MapIcon.Type iconType;
+ @Shadow
+ private int maxUses;
+ @Shadow
+ private int experience;
+
+ @Overwrite
+ public TradeOffer create(Entity entity, Random random) {
+ if (!(entity.world instanceof ServerWorld)) {
+ return null;
+ } else {
+ ServerWorld serverWorld = (ServerWorld) entity.world;
+ BlockPos blockPos = new BlockPos(0,0,0);
+ ItemStack itemStack = FilledMapItem.createMap(serverWorld, blockPos.getX(), blockPos.getZ(), (byte)2, true, true);
+ FilledMapItem.fillExplorationMap(serverWorld, itemStack);
+ MapState.addDecorationsTag(itemStack, blockPos, "+", this.iconType);
+ itemStack.setCustomName(new LiteralText("You shall not crash"));
+ return new TradeOffer(new ItemStack(Items.EMERALD, this.price), new ItemStack(Items.COMPASS), itemStack, this.maxUses, this.experience, 0.2F);
+ }
+ }
+}
+
diff --git a/src/main/resources/parquet.mixins.json b/src/main/resources/parquet.mixins.json
index 93d9905..5d809a4 100644
--- a/src/main/resources/parquet.mixins.json
+++ b/src/main/resources/parquet.mixins.json
@@ -10,7 +10,8 @@
"CommandManagerMixin",
"ServerPlayerEntityMixin",
"BootstrapMixin",
- "FireWorkItemMixin"
+ "FireWorkItemMixin",
+ "SellMapFactoryMixin"
],
"client": [
],