Skip to content

Commit c0326f4

Browse files
authored
Merge pull request #3 from Heyh520/1.21.1
fix: player join/death/block break issues with handlePong,CraftChunk,…
2 parents afa6162 + 2738964 commit c0326f4

10 files changed

Lines changed: 1161 additions & 15 deletions

File tree

projects/neotaiyitist/build.gradle

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ dependencies {
138138
libraries "org.hamcrest:hamcrest:2.2"
139139
libraries "org.mockito:mockito-core:5.14.1"
140140
libraries "org.yaml:snakeyaml:2.2"
141+
libraries "com.github.lalyos:jfiglet:0.0.9"
141142
libraries ("net.md-5:bungeecord-chat:1.21-R0.3") {
142143
transitive = false
143144
}
@@ -181,14 +182,15 @@ neoDev {
181182
configureEach {
182183
gameDirectory = layout.projectDir.dir("run/$name")
183184
systemProperty("terminal.ansi", "true")
185+
jvmArguments.addAll '-Xms4G', '-Xmx6G'
184186
}
185-
client {
187+
client {
186188
client()
187-
}
189+
}
188190

189-
server {
191+
server {
190192
server()
191-
}
193+
}
192194

193195
gameTestServer {
194196
type = "gameTestServer"
@@ -207,6 +209,11 @@ tasks.withType(JavaCompile.class).configureEach {
207209
options.forkOptions.memoryMaximumSize = '2g'
208210
}
209211

212+
// Keep Gradle connected to server process for console input
213+
tasks.matching { it.name == 'runServer' }.configureEach {
214+
standardInput = System.in
215+
}
216+
210217
tasks.withType(Javadoc.class).configureEach {
211218
options.tags = [
212219
'apiNote:a:<em>API Note:</em>',

src/main/java/org/bukkit/craftbukkit/CraftChunk.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class CraftChunk implements Chunk {
6161
private static final byte[] EMPTY_LIGHT = new byte[2048];
6262

6363
public CraftChunk(net.minecraft.world.level.chunk.LevelChunk chunk) {
64-
this.worldServer = null; //NeoTaiyitist - TODO fixme
64+
this.worldServer = (ServerLevel) chunk.getLevel();
6565
this.x = chunk.getPos().x;
6666
this.z = chunk.getPos().z;
6767
}
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.taiyitistmc;
22

3+
import com.github.lalyos.jfiglet.FigletFont;
34
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion;
45
import org.apache.logging.log4j.LogManager;
56
import org.apache.logging.log4j.Logger;
67

8+
import java.io.InputStream;
79
import java.time.ZoneId;
810

911
public class NeoTaiyitist {
@@ -12,18 +14,24 @@ public class NeoTaiyitist {
1214
public static final Logger LOGGER = LogManager.getLogger();
1315
public static final float javaVersion = Float.parseFloat(System.getProperty("java.class.version"));
1416

17+
// ANSI color codes
18+
private static final String CYAN = "\u001B[36m";
19+
private static final String YELLOW = "\u001B[33m";
20+
private static final String RESET = "\u001B[0m";
21+
1522
public static void run() throws Exception {
16-
LOGGER.info(" _____ ___ _ __ __ _ _____ _ _____ _____ ");
17-
LOGGER.info("|_ _| / | | | \\ \\ / / | | |_ _| | | / ___/ |_ _| ");
18-
LOGGER.info(" | | / /| | | | \\ \\/ / | | | | | | | |___ | | ");
19-
LOGGER.info(" | | / /_| | | | \\ / | | | | | | \\___ \\ | | ");
20-
LOGGER.info(" | | / ___ | | | / / | | | | | | ___| | | | ");
21-
LOGGER.info(" |_| /_/ |_| |_| /_/ |_| |_| |_| /_____/ |_| ");
22-
LOGGER.info("{} {}, Java {}", "Welecom to NeoTaiyitist for neoforge", NeoForgeVersion.getVersion(), javaVersion);
23+
InputStream fontStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("larry3d.flf");
24+
String banner = FigletFont.convertOneLine(fontStream, "NeoTaiyitist");
25+
for (String line : banner.split("\n")) {
26+
System.out.println(CYAN + line + RESET);
27+
}
28+
29+
System.out.println(YELLOW + "Welcome to NeoTaiyitist for NeoForge " + NeoForgeVersion.getVersion() + ", Java " + javaVersion + RESET);
30+
2331
ZoneId zoneId = ZoneId.of("Asia/Shanghai");
24-
if(zoneId.getId().contains("China")) {
25-
System.out.printf("官方交流QQ群: 211128424%n");
26-
System.out.printf("如果控制台出现中文乱码请添加启动参数: -Dfile.encoding=GBK%n");
32+
if (zoneId.getId().contains("China")) {
33+
System.out.println("官方交流QQ群: 211128424");
34+
System.out.println("如果控制台出现中文乱码请添加启动参数: -Dfile.encoding=GBK%n");
2735
}
2836
}
2937
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.taiyitistmc.injection.world.food;
2+
3+
4+
public interface InjectionFoodProperties {
5+
// Marker interface - no additional methods required currently
6+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.taiyitistmc.mixin.server.network;
2+
3+
import net.minecraft.network.protocol.PacketUtils;
4+
import net.minecraft.network.protocol.common.ServerboundPongPacket;
5+
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
6+
import net.minecraft.util.thread.ReentrantBlockableEventLoop;
7+
import net.neoforged.neoforge.common.extensions.ICommonPacketListener;
8+
import net.neoforged.neoforge.network.registration.NetworkRegistry;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.Shadow;
11+
12+
@Mixin(ServerConfigurationPacketListenerImpl.class)
13+
public abstract class MixinServerConfigurationPacketListenerImpl {
14+
15+
@Shadow
16+
private void runConfiguration() {
17+
throw new AssertionError();
18+
}
19+
20+
public void handlePong(ServerboundPongPacket packet) {
21+
ICommonPacketListener self = (ICommonPacketListener) this;
22+
23+
// Ensure we run on the main server thread
24+
PacketUtils.ensureRunningOnSameThread(packet, (ServerConfigurationPacketListenerImpl) (Object) this, (ReentrantBlockableEventLoop<?>) self.getMainThreadEventLoop());
25+
26+
if (packet.getId() == 0) {
27+
if (!self.getConnectionType().isNeoForge()) {
28+
if (!NetworkRegistry.initializeOtherConnection((ServerConfigurationPacketListenerImpl) (Object) this)) {
29+
return;
30+
}
31+
}
32+
this.runConfiguration();
33+
}
34+
}
35+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package org.taiyitistmc.mixin.world.inventory;
2+
3+
import net.minecraft.network.chat.Component;
4+
import net.minecraft.world.inventory.AbstractContainerMenu;
5+
import net.minecraft.world.inventory.ContainerSynchronizer;
6+
import net.minecraft.world.item.ItemStack;
7+
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
8+
import org.bukkit.craftbukkit.inventory.CraftInventory;
9+
import org.bukkit.inventory.InventoryView;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.Shadow;
12+
import org.spongepowered.asm.mixin.Unique;
13+
import org.spongepowered.asm.mixin.injection.At;
14+
import org.spongepowered.asm.mixin.injection.Inject;
15+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
16+
17+
import javax.annotation.Nullable;
18+
19+
@Mixin(AbstractContainerMenu.class)
20+
public abstract class MixinAbstractContainerMenu {
21+
22+
@Shadow
23+
private ItemStack remoteCarried;
24+
25+
@Shadow
26+
@Nullable
27+
private ContainerSynchronizer synchronizer;
28+
29+
@Shadow
30+
public abstract ItemStack getCarried();
31+
32+
@Unique
33+
private Component title;
34+
35+
@Unique
36+
private InventoryView bukkitView;
37+
38+
39+
// This provides a fallback that returns null
40+
public InventoryView getBukkitView() {
41+
return this.bukkitView;
42+
}
43+
44+
public void setBukkitView(InventoryView view) {
45+
this.bukkitView = view;
46+
}
47+
48+
public void transferTo(AbstractContainerMenu other, CraftHumanEntity player) {
49+
InventoryView source = this.getBukkitView();
50+
InventoryView destination = other.getBukkitView();
51+
if (source != null) {
52+
((CraftInventory) source.getTopInventory()).getInventory().onClose(player);
53+
((CraftInventory) source.getBottomInventory()).getInventory().onClose(player);
54+
}
55+
if (destination != null) {
56+
((CraftInventory) destination.getTopInventory()).getInventory().onOpen(player);
57+
((CraftInventory) destination.getBottomInventory()).getInventory().onOpen(player);
58+
}
59+
}
60+
61+
public Component getTitle() {
62+
if (this.title == null) {
63+
return Component.empty();
64+
}
65+
return this.title;
66+
}
67+
68+
public void setTitle(Component title) {
69+
this.title = title;
70+
}
71+
72+
public void broadcastCarriedItem() {
73+
ItemStack carried = this.getCarried();
74+
this.remoteCarried = carried.copy();
75+
if (this.synchronizer != null) {
76+
this.synchronizer.sendCarriedChange((AbstractContainerMenu) (Object) this, carried.copy());
77+
}
78+
}
79+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.taiyitistmc.mixin.world.inventory;
2+
3+
import net.minecraft.world.entity.player.Inventory;
4+
import net.minecraft.world.entity.player.Player;
5+
import net.minecraft.world.inventory.AbstractContainerMenu;
6+
import net.minecraft.world.inventory.CraftingContainer;
7+
import net.minecraft.world.inventory.InventoryMenu;
8+
import net.minecraft.world.inventory.MenuType;
9+
import net.minecraft.world.inventory.ResultContainer;
10+
import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
11+
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
12+
import org.jetbrains.annotations.Nullable;
13+
import org.spongepowered.asm.mixin.Final;
14+
import org.spongepowered.asm.mixin.Mixin;
15+
import org.spongepowered.asm.mixin.Shadow;
16+
import org.spongepowered.asm.mixin.Unique;
17+
import org.spongepowered.asm.mixin.injection.At;
18+
import org.spongepowered.asm.mixin.injection.Inject;
19+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
20+
21+
@Mixin(InventoryMenu.class)
22+
public abstract class MixinInventoryMenu extends AbstractContainerMenu {
23+
24+
@Shadow
25+
@Final
26+
private CraftingContainer craftSlots;
27+
28+
@Shadow
29+
@Final
30+
private ResultContainer resultSlots;
31+
32+
@Shadow
33+
@Final
34+
public Player owner;
35+
36+
@Unique
37+
private CraftInventoryView bukkitEntity;
38+
39+
protected MixinInventoryMenu(@Nullable MenuType<?> menuType, int i) {
40+
super(menuType, i);
41+
}
42+
43+
@Inject(method = "stillValid", cancellable = true, at = @At("HEAD"))
44+
public void taiyitist$unreachable(Player playerIn, CallbackInfoReturnable<Boolean> cir) {
45+
if (!checkReachable) cir.setReturnValue(true);
46+
}
47+
48+
@Override
49+
public CraftInventoryView getBukkitView() {
50+
if (bukkitEntity != null) {
51+
return bukkitEntity;
52+
}
53+
54+
CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftSlots, this.resultSlots);
55+
bukkitEntity = new CraftInventoryView(this.owner.getBukkitEntity(), inventory, (InventoryMenu) (Object) this);
56+
return bukkitEntity;
57+
}
58+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.taiyitistmc.mixin.world.level.block;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.server.level.ServerLevel;
5+
import net.minecraft.util.valueproviders.IntProvider;
6+
import net.minecraft.world.item.ItemStack;
7+
import net.minecraft.world.item.enchantment.EnchantmentHelper;
8+
import net.minecraft.world.level.block.Block;
9+
import net.minecraft.world.level.block.state.BlockState;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
12+
@Mixin(Block.class)
13+
public abstract class MixinBlock {
14+
15+
16+
public int getExpDrop(BlockState blockState, ServerLevel world, BlockPos blockPos, ItemStack itemStack, boolean flag) {
17+
return 0;
18+
}
19+
20+
21+
public int taiyitist$tryDropExperience(ServerLevel level, BlockPos pos, ItemStack heldItem, IntProvider amount) {
22+
int i = EnchantmentHelper.processBlockExperience(level, heldItem, amount.sample(level.getRandom()));
23+
return i;
24+
}
25+
}

0 commit comments

Comments
 (0)