Skip to content

Commit

Permalink
Fix world generating exceptions.
Browse files Browse the repository at this point in the history
Signed-off-by: 秋雨落 <[email protected]>
  • Loading branch information
qyl27 committed Sep 15, 2024
1 parent c1c0349 commit 0f1a822
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.izzel.arclight.common.mixin.bukkit.util;

import io.izzel.arclight.common.bridge.core.world.IWorldWriterBridge;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.LevelAccessor;
import org.bukkit.craftbukkit.v.util.BlockStateListPopulator;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(BlockStateListPopulator.class)
public class BlockStateListPopulatorMixin implements IWorldWriterBridge {
@Shadow @Final private LevelAccessor world;

@Override
public boolean bridge$addEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
return ((IWorldWriterBridge) world).bridge$addEntity(entity, reason);
}

@Override
public void bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason reason) {
((IWorldWriterBridge) world).bridge$pushAddEntityReason(reason);
}

@Override
public CreatureSpawnEvent.SpawnReason bridge$getAddEntityReason() {
return ((IWorldWriterBridge) world).bridge$getAddEntityReason();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.izzel.arclight.common.mixin.bukkit.util;

import io.izzel.arclight.common.bridge.core.world.IWorldWriterBridge;
import io.izzel.arclight.common.bridge.core.world.WorldBridge;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.WorldGenLevel;
import org.bukkit.craftbukkit.v.util.DelegatedGeneratorAccess;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(DelegatedGeneratorAccess.class)
public abstract class DelegatedGeneratorAccessMixin implements IWorldWriterBridge {
@Shadow public abstract WorldGenLevel getHandle();

@Override
public boolean bridge$addEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
if (getHandle() != (Object) this) {
return ((IWorldWriterBridge) getHandle()).bridge$addEntity(entity, reason);
} else {
this.bridge$pushAddEntityReason(reason);
return getHandle().addFreshEntity(entity);
}
}

@Override
public void bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason reason) {
if (getHandle() != (Object) this) {
((IWorldWriterBridge) getHandle()).bridge$pushAddEntityReason(reason);
}
}

@Override
public CreatureSpawnEvent.SpawnReason bridge$getAddEntityReason() {
if (getHandle() != (Object) this) {
return ((IWorldWriterBridge) getHandle()).bridge$getAddEntityReason();
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.izzel.arclight.common.mixin.bukkit.util;

import io.izzel.arclight.common.bridge.core.world.IWorldWriterBridge;
import net.minecraft.world.entity.Entity;
import org.bukkit.craftbukkit.v.util.DummyGeneratorAccess;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(DummyGeneratorAccess.class)
public class DummyGeneratorAccessMixin implements IWorldWriterBridge {
@Override
public boolean bridge$addEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public void bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason reason) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public CreatureSpawnEvent.SpawnReason bridge$getAddEntityReason() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import net.minecraft.world.item.trading.MerchantOffers;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftAbstractVillager;
import org.bukkit.craftbukkit.v.inventory.CraftMerchant;
import org.bukkit.craftbukkit.v.inventory.CraftMerchantRecipe;
import org.bukkit.entity.AbstractVillager;
Expand Down Expand Up @@ -37,7 +39,7 @@ public abstract class AbstractVillagerMixin extends PathfinderMobMixin implement

@Override
public CraftMerchant bridge$getCraftMerchant() {
return (craftMerchant == null) ? craftMerchant = new CraftMerchant((net.minecraft.world.entity.npc.AbstractVillager) (Object) this) : craftMerchant;
return (craftMerchant == null) ? craftMerchant = new CraftAbstractVillager(((CraftServer) Bukkit.getServer()), (net.minecraft.world.entity.npc.AbstractVillager) (Object) this) : craftMerchant;
}

@Redirect(method = "addOffersFromItemListings", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/trading/MerchantOffers;add(Ljava/lang/Object;)Z"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"PotionTypeMixin",
"Registry_SimpleRegistryMixin",
"StandardMessengerMixin",
"WatchdogThreadMixin"
"WatchdogThreadMixin",
"util.BlockStateListPopulatorMixin",
"util.DelegatedGeneratorAccessMixin",
"util.DummyGeneratorAccessMixin"
]
}

0 comments on commit 0f1a822

Please sign in to comment.