1.17: items, player, network, server

This commit is contained in:
IzzelAliz 2021-07-25 17:47:10 +08:00
parent e3a2790709
commit f83cf94337
122 changed files with 1652 additions and 1739 deletions

View File

@ -8,7 +8,8 @@ buildscript {
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: "${forge_gradle_version}"
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
classpath "io.izzel.arclight:arclight-gradle-plugin:$agpVersion"
// classpath "io.izzel.arclight:arclight-gradle-plugin:$agpVersion"
classpath files("G:\\workspace\\arclight-gradle-plugin\\build\\libs\\arclight-gradle-plugin-1.18.jar")
}
}

View File

@ -1,418 +0,0 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge;
import io.izzel.arclight.common.bridge.inventory.container.SlotBridge;
import io.izzel.arclight.common.mod.server.ArclightContainer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v.inventory.CraftInventory;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
@Mixin(AbstractContainerMenu.class)
public abstract class ContainerMixin implements ContainerBridge {
// @formatter:off
@Shadow public void broadcastChanges() {}
@Shadow private int quickcraftStatus;
@Shadow protected abstract void resetQuickCraft();
@Shadow private int quickcraftType;
@Shadow @Final private Set<Slot> quickcraftSlots;
@Shadow public List<Slot> slots;
@Shadow public abstract boolean canDragTo(Slot slotIn);
@Shadow public abstract ItemStack quickMoveStack(Player playerIn, int index);
@Shadow public abstract boolean canTakeItemForPickAll(ItemStack stack, Slot slotIn);
@Shadow @Final public int containerId;
@Shadow public abstract Slot getSlot(int slotId);
@Shadow public static int getQuickcraftHeader(int clickedButton) { return 0; }
@Shadow public static int getQuickcraftType(int eventButton) { return 0; }
@Shadow public static boolean isValidQuickcraftType(int dragModeIn, Player player) { return false; }
@Shadow public static boolean canItemQuickReplace(@Nullable Slot slotIn, ItemStack stack, boolean stackSizeMatters) { return false; }
@Shadow public static void getQuickCraftSlotCount(Set<Slot> dragSlotsIn, int dragModeIn, ItemStack stack, int slotStackSize) { }
@Shadow public static boolean consideredTheSameItem(ItemStack stack1, ItemStack stack2) { return false; }
@Shadow protected abstract boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection);
@Shadow @Final @javax.annotation.Nullable private MenuType<?> menuType;
// @formatter:on
public boolean checkReachable = true;
private InventoryView bukkitView;
private long bukkitViewHash = 0;
public InventoryView getBukkitView() {
if (bukkitView != null && bukkitViewHash != bukkitViewHash()) {
ArclightContainer.updateView((AbstractContainerMenu) (Object) this, bukkitView);
bukkitViewHash = bukkitViewHash();
}
if (bukkitView == null) {
bukkitView = ArclightContainer.createInvView((AbstractContainerMenu) (Object) this);
bukkitViewHash = bukkitViewHash();
}
return bukkitView;
}
private long bukkitViewHash() {
return (((long) this.slots.size()) << 32) | System.identityHashCode(this.slots);
}
public void transferTo(AbstractContainerMenu other, CraftHumanEntity player) {
InventoryView source = this.getBukkitView();
InventoryView destination = ((ContainerBridge) other).bridge$getBukkitView();
((IInventoryBridge) ((CraftInventory) source.getTopInventory()).getInventory()).onClose(player);
((IInventoryBridge) ((CraftInventory) source.getBottomInventory()).getInventory()).onClose(player);
((IInventoryBridge) ((CraftInventory) destination.getTopInventory()).getInventory()).onOpen(player);
((IInventoryBridge) ((CraftInventory) destination.getBottomInventory()).getInventory()).onOpen(player);
}
private Component title;
public final Component getTitle() {
if (this.title == null) {
if (this.menuType != null && this.menuType.getRegistryName() != null) {
return new TextComponent(this.menuType.getRegistryName().toString());
} else {
return new TextComponent(this.toString());
}
}
return this.title;
}
public final void setTitle(Component title) {
if (this.title == null) {
if (title == null) {
this.title = getTitle();
} else {
this.title = title;
}
}
}
@Redirect(method = "removed", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;drop(Lnet/minecraft/world/item/ItemStack;Z)Lnet/minecraft/world/entity/item/ItemEntity;"))
private ItemEntity arclight$cleanBeforeDrop(Player playerEntity, ItemStack itemStackIn, boolean unused) {
playerEntity.inventory.setCarried(ItemStack.EMPTY);
return playerEntity.drop(itemStackIn, unused);
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private ItemStack doClick(int slotId, int dragType, ClickType clickTypeIn, Player player) {
ItemStack itemstack = ItemStack.EMPTY;
Inventory playerinventory = player.inventory;
if (clickTypeIn == ClickType.QUICK_CRAFT) {
int j1 = this.quickcraftStatus;
this.quickcraftStatus = getQuickcraftHeader(dragType);
if ((j1 != 1 || this.quickcraftStatus != 2) && j1 != this.quickcraftStatus) {
this.resetQuickCraft();
} else if (playerinventory.getCarried().isEmpty()) {
this.resetQuickCraft();
} else if (this.quickcraftStatus == 0) {
this.quickcraftType = getQuickcraftType(dragType);
if (isValidQuickcraftType(this.quickcraftType, player)) {
this.quickcraftStatus = 1;
this.quickcraftSlots.clear();
} else {
this.resetQuickCraft();
}
} else if (this.quickcraftStatus == 1) {
Slot slot7 = this.slots.get(slotId);
ItemStack itemstack12 = playerinventory.getCarried();
if (slot7 != null && canItemQuickReplace(slot7, itemstack12, true) && slot7.mayPlace(itemstack12) && (this.quickcraftType == 2 || itemstack12.getCount() > this.quickcraftSlots.size()) && this.canDragTo(slot7)) {
this.quickcraftSlots.add(slot7);
}
} else if (this.quickcraftStatus == 2) {
if (!this.quickcraftSlots.isEmpty()) {
ItemStack itemstack9 = playerinventory.getCarried().copy();
int k1 = playerinventory.getCarried().getCount();
Map<Integer, ItemStack> draggedSlots = new HashMap<>();
for (Slot slot8 : this.quickcraftSlots) {
ItemStack itemstack13 = playerinventory.getCarried();
if (slot8 != null && canItemQuickReplace(slot8, itemstack13, true) && slot8.mayPlace(itemstack13) && (this.quickcraftType == 2 || itemstack13.getCount() >= this.quickcraftSlots.size()) && this.canDragTo(slot8)) {
ItemStack itemstack14 = itemstack9.copy();
int j3 = slot8.hasItem() ? slot8.getItem().getCount() : 0;
getQuickCraftSlotCount(this.quickcraftSlots, this.quickcraftType, itemstack14, j3);
int k3 = Math.min(itemstack14.getMaxStackSize(), slot8.getMaxStackSize(itemstack14));
if (itemstack14.getCount() > k3) {
itemstack14.setCount(k3);
}
k1 -= itemstack14.getCount() - j3;
// slot8.putStack(itemstack14);
draggedSlots.put(slot8.index, itemstack14);
}
}
InventoryView view = this.getBukkitView();
org.bukkit.inventory.ItemStack newcursor = CraftItemStack.asCraftMirror(itemstack9);
newcursor.setAmount(k1);
Map<Integer, org.bukkit.inventory.ItemStack> eventmap = new HashMap<>();
for (Map.Entry<Integer, ItemStack> ditem : draggedSlots.entrySet()) {
eventmap.put(ditem.getKey(), CraftItemStack.asBukkitCopy(ditem.getValue()));
}
ItemStack oldCursor = playerinventory.getCarried();
playerinventory.setCarried(CraftItemStack.asNMSCopy(newcursor));
InventoryDragEvent event = new InventoryDragEvent(view, (newcursor.getType() != Material.AIR) ? newcursor : null, CraftItemStack.asBukkitCopy(oldCursor), this.quickcraftType == 1, eventmap);
Bukkit.getPluginManager().callEvent(event);
boolean needsUpdate = event.getResult() != Event.Result.DEFAULT;
if (event.getResult() != Event.Result.DENY) {
for (Map.Entry<Integer, ItemStack> dslot : draggedSlots.entrySet()) {
view.setItem(dslot.getKey(), CraftItemStack.asBukkitCopy(dslot.getValue()));
}
if (playerinventory.getCarried() != null) {
playerinventory.setCarried(CraftItemStack.asNMSCopy(event.getCursor()));
needsUpdate = true;
}
} else {
playerinventory.setCarried(oldCursor);
}
if (needsUpdate && player instanceof ServerPlayer) {
((ServerPlayer) player).refreshContainer((AbstractContainerMenu) (Object) this);
}
}
this.resetQuickCraft();
} else {
this.resetQuickCraft();
}
} else if (this.quickcraftStatus != 0) {
this.resetQuickCraft();
} else if ((clickTypeIn == ClickType.PICKUP || clickTypeIn == ClickType.QUICK_MOVE) && (dragType == 0 || dragType == 1)) {
if (slotId == -999) {
if (!playerinventory.getCarried().isEmpty()) {
if (dragType == 0) {
ItemStack carried = playerinventory.getCarried();
playerinventory.setCarried(ItemStack.EMPTY);
player.drop(carried, true);
}
if (dragType == 1) {
player.drop(playerinventory.getCarried().split(1), true);
}
}
} else if (clickTypeIn == ClickType.QUICK_MOVE) {
if (slotId < 0) {
return ItemStack.EMPTY;
}
Slot slot5 = this.slots.get(slotId);
if (slot5 == null || !slot5.mayPickup(player)) {
return ItemStack.EMPTY;
}
for (ItemStack itemstack7 = this.quickMoveStack(player, slotId); !itemstack7.isEmpty() && ItemStack.isSame(slot5.getItem(), itemstack7); itemstack7 = this.quickMoveStack(player, slotId)) {
itemstack = itemstack7.copy();
}
} else {
if (slotId < 0) {
return ItemStack.EMPTY;
}
Slot slot6 = this.slots.get(slotId);
if (slot6 != null) {
ItemStack itemstack8 = slot6.getItem();
ItemStack itemstack11 = playerinventory.getCarried();
if (!itemstack8.isEmpty()) {
itemstack = itemstack8.copy();
}
if (itemstack8.isEmpty()) {
if (!itemstack11.isEmpty() && slot6.mayPlace(itemstack11)) {
int j2 = dragType == 0 ? itemstack11.getCount() : 1;
if (j2 > slot6.getMaxStackSize(itemstack11)) {
j2 = slot6.getMaxStackSize(itemstack11);
}
slot6.set(itemstack11.split(j2));
}
} else if (slot6.mayPickup(player)) {
if (itemstack11.isEmpty()) {
if (itemstack8.isEmpty()) {
slot6.set(ItemStack.EMPTY);
playerinventory.setCarried(ItemStack.EMPTY);
} else {
int k2 = dragType == 0 ? itemstack8.getCount() : (itemstack8.getCount() + 1) / 2;
playerinventory.setCarried(slot6.remove(k2));
if (itemstack8.isEmpty()) {
slot6.set(ItemStack.EMPTY);
}
slot6.onTake(player, playerinventory.getCarried());
}
} else if (slot6.mayPlace(itemstack11)) {
if (consideredTheSameItem(itemstack8, itemstack11)) {
int l2 = dragType == 0 ? itemstack11.getCount() : 1;
if (l2 > slot6.getMaxStackSize(itemstack11) - itemstack8.getCount()) {
l2 = slot6.getMaxStackSize(itemstack11) - itemstack8.getCount();
}
if (l2 > itemstack11.getMaxStackSize() - itemstack8.getCount()) {
l2 = itemstack11.getMaxStackSize() - itemstack8.getCount();
}
itemstack11.shrink(l2);
itemstack8.grow(l2);
} else if (itemstack11.getCount() <= slot6.getMaxStackSize(itemstack11)) {
slot6.set(itemstack11);
playerinventory.setCarried(itemstack8);
}
} else if (itemstack11.getMaxStackSize() > 1 && consideredTheSameItem(itemstack8, itemstack11) && !itemstack8.isEmpty()) {
int i3 = itemstack8.getCount();
if (i3 + itemstack11.getCount() <= itemstack11.getMaxStackSize()) {
itemstack11.grow(i3);
itemstack8 = slot6.remove(i3);
if (itemstack8.isEmpty()) {
slot6.set(ItemStack.EMPTY);
}
slot6.onTake(player, playerinventory.getCarried());
}
}
}
slot6.setChanged();
if (player instanceof ServerPlayer && slot6.getMaxStackSize() != 64) {
((ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, slot6.index, slot6.getItem()));
if (this.getBukkitView().getType() == InventoryType.WORKBENCH || this.getBukkitView().getType() == InventoryType.CRAFTING) {
((ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, 0, this.getSlot(0).getItem()));
}
}
}
}
} else if (clickTypeIn == ClickType.SWAP && dragType >= 0 && dragType < 9) {
Slot slot4 = this.slots.get(slotId);
ItemStack itemstack6 = playerinventory.getItem(dragType);
ItemStack itemstack10 = slot4.getItem();
if (!itemstack6.isEmpty() || !itemstack10.isEmpty()) {
if (itemstack6.isEmpty()) {
if (slot4.mayPickup(player)) {
playerinventory.setItem(dragType, itemstack10);
((SlotBridge) slot4).bridge$onSwapCraft(itemstack10.getCount());
slot4.set(ItemStack.EMPTY);
slot4.onTake(player, itemstack10);
}
} else if (itemstack10.isEmpty()) {
if (slot4.mayPlace(itemstack6)) {
int l1 = slot4.getMaxStackSize(itemstack6);
if (itemstack6.getCount() > l1) {
slot4.set(itemstack6.split(l1));
} else {
slot4.set(itemstack6);
playerinventory.setItem(dragType, ItemStack.EMPTY);
}
}
} else if (slot4.mayPickup(player) && slot4.mayPlace(itemstack6)) {
int i2 = slot4.getMaxStackSize(itemstack6);
if (itemstack6.getCount() > i2) {
slot4.set(itemstack6.split(i2));
slot4.onTake(player, itemstack10);
if (!playerinventory.add(itemstack10)) {
player.drop(itemstack10, true);
}
} else {
slot4.set(itemstack6);
playerinventory.setItem(dragType, itemstack10);
slot4.onTake(player, itemstack10);
}
}
}
} else if (clickTypeIn == ClickType.CLONE && player.abilities.instabuild && playerinventory.getCarried().isEmpty() && slotId >= 0) {
Slot slot3 = this.slots.get(slotId);
if (slot3 != null && slot3.hasItem()) {
ItemStack itemstack5 = slot3.getItem().copy();
itemstack5.setCount(itemstack5.getMaxStackSize());
playerinventory.setCarried(itemstack5);
}
} else if (clickTypeIn == ClickType.THROW && playerinventory.getCarried().isEmpty() && slotId >= 0) {
Slot slot2 = this.slots.get(slotId);
if (slot2 != null && slot2.hasItem() && slot2.mayPickup(player)) {
ItemStack itemstack4 = slot2.remove(dragType == 0 ? 1 : slot2.getItem().getCount());
slot2.onTake(player, itemstack4);
player.drop(itemstack4, true);
}
} else if (clickTypeIn == ClickType.PICKUP_ALL && slotId >= 0) {
Slot slot = this.slots.get(slotId);
ItemStack itemstack1 = playerinventory.getCarried();
if (!itemstack1.isEmpty() && (slot == null || !slot.hasItem() || !slot.mayPickup(player))) {
int i = dragType == 0 ? 0 : this.slots.size() - 1;
int j = dragType == 0 ? 1 : -1;
for (int k = 0; k < 2; ++k) {
for (int l = i; l >= 0 && l < this.slots.size() && itemstack1.getCount() < itemstack1.getMaxStackSize(); l += j) {
Slot slot1 = this.slots.get(l);
if (slot1.hasItem() && canItemQuickReplace(slot1, itemstack1, true) && slot1.mayPickup(player) && this.canTakeItemForPickAll(itemstack1, slot1)) {
ItemStack itemstack2 = slot1.getItem();
if (k != 0 || itemstack2.getCount() != itemstack2.getMaxStackSize()) {
int i1 = Math.min(itemstack1.getMaxStackSize() - itemstack1.getCount(), itemstack2.getCount());
ItemStack itemstack3 = slot1.remove(i1);
itemstack1.grow(i1);
if (itemstack3.isEmpty()) {
slot1.set(ItemStack.EMPTY);
}
slot1.onTake(player, itemstack3);
}
}
}
}
}
this.broadcastChanges();
}
return itemstack;
}
@Override
public boolean bridge$isCheckReachable() {
return checkReachable;
}
@Override
public InventoryView bridge$getBukkitView() {
return getBukkitView();
}
@Override
public void bridge$transferTo(AbstractContainerMenu other, CraftHumanEntity player) {
transferTo(other, player);
}
@Override
public Component bridge$getTitle() {
return getTitle();
}
@Override
public void bridge$setTitle(Component title) {
setTitle(title);
}
}

View File

@ -1,57 +0,0 @@
package io.izzel.arclight.common.mixin.core.item;
import io.izzel.arclight.common.bridge.world.storage.MapDataBridge;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.MapItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import org.bukkit.Bukkit;
import org.bukkit.event.server.MapInitializeEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(MapItem.class)
public abstract class FilledMapItemMixin {
// @formatter:off
@Shadow private static MapItemSavedData createAndStoreSavedData(ItemStack stack, Level worldIn, int x, int z, int scale, boolean trackingPosition, boolean unlimitedTracking, ResourceKey<Level> dimensionTypeIn) { return null; }
// @formatter:on
@Inject(method = "createAndStoreSavedData", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN"))
private static void arclight$mapInit(ItemStack stack, Level worldIn, int x, int z, int scale, boolean trackingPosition,
boolean unlimitedTracking, ResourceKey<Level> dimensionTypeIn, CallbackInfoReturnable<MapItemSavedData> cir,
int i, MapItemSavedData mapData) {
MapInitializeEvent event = new MapInitializeEvent(((MapDataBridge) mapData).bridge$getMapView());
Bukkit.getPluginManager().callEvent(event);
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static int getMapId(ItemStack stack) {
CompoundTag compoundnbt = stack.getTag();
return compoundnbt != null && compoundnbt.contains("map", 99) ? compoundnbt.getInt("map") : -1;
}
@Inject(method = "getOrCreateSavedData", cancellable = true, at = @At("HEAD"))
private static void arclight$nonFilledMap(ItemStack stack, Level worldIn, CallbackInfoReturnable<MapItemSavedData> cir) {
if (stack != null && worldIn instanceof ServerLevel && stack.getItem() == Items.MAP) {
MapItemSavedData mapdata = MapItem.getSavedData(stack, worldIn);
if (mapdata == null) {
mapdata = createAndStoreSavedData(stack, worldIn, worldIn.getLevelData().getXSpawn(), worldIn.getLevelData().getZSpawn(), 3, false, false, worldIn.dimension());
}
cir.setReturnValue(mapdata);
}
}
}

View File

@ -3,15 +3,15 @@ package io.izzel.arclight.common.mixin.core.network;
import com.mojang.authlib.properties.Property;
import io.izzel.arclight.common.bridge.network.NetworkManagerBridge;
import io.netty.channel.Channel;
import net.minecraft.network.Connection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.net.SocketAddress;
import java.util.UUID;
import net.minecraft.network.Connection;
@Mixin(Connection.class)
public class NetworkManagerMixin implements NetworkManagerBridge {
public class ConnectionMixin implements NetworkManagerBridge {
@Shadow public Channel channel;
public java.util.UUID spoofedUUID;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.network.handshake;
package io.izzel.arclight.common.mixin.core.network;
import com.google.gson.Gson;
import com.mojang.authlib.properties.Property;
@ -16,7 +16,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerHandshakePacketListenerImpl;
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
import net.minecraft.server.network.ServerStatusPacketListenerImpl;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import net.minecraftforge.fmllegacy.server.ServerLifecycleHooks;
import org.apache.logging.log4j.LogManager;
import org.bukkit.Bukkit;
import org.spigotmc.SpigotConfig;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.network.login;
package io.izzel.arclight.common.mixin.core.network;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
@ -11,6 +11,7 @@ import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.protocol.game.ClientboundDisconnectPacket;
import net.minecraft.network.protocol.login.ClientboundGameProfilePacket;
import net.minecraft.network.protocol.login.ClientboundHelloPacket;
import net.minecraft.network.protocol.login.ClientboundLoginCompressionPacket;
@ -23,7 +24,7 @@ import net.minecraft.server.network.ServerLoginPacketListenerImpl;
import net.minecraft.util.Crypt;
import net.minecraft.util.CryptException;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.fml.common.thread.SidedThreadGroups;
import net.minecraftforge.fml.util.thread.SidedThreadGroups;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
@ -55,7 +56,6 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle
@Shadow private ServerLoginPacketListenerImpl.State state;
@Shadow @Final private MinecraftServer server;
@Shadow @Final private byte[] nonce;
@Shadow private SecretKey secretKey;
@Shadow @Final public Connection connection;
@Shadow @Final private static AtomicInteger UNIQUE_THREAD_ID;
@Shadow private GameProfile gameProfile;
@ -108,17 +108,24 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle
this.state = ServerLoginPacketListenerImpl.State.ACCEPTED;
if (this.server.getCompressionThreshold() >= 0 && !this.connection.isMemoryConnection()) {
this.connection.send(new ClientboundLoginCompressionPacket(this.server.getCompressionThreshold()), (p_210149_1_) -> {
this.connection.setupCompression(this.server.getCompressionThreshold());
this.connection.setupCompression(this.server.getCompressionThreshold(), true);
});
}
this.connection.send(new ClientboundGameProfilePacket(this.gameProfile));
ServerPlayer serverplayerentity = this.server.getPlayerList().getPlayer(this.gameProfile.getId());
if (serverplayerentity != null) {
this.state = ServerLoginPacketListenerImpl.State.DELAY_ACCEPT;
this.delayedAcceptPlayer = entity;
} else {
this.server.getPlayerList().placeNewPlayer(this.connection, entity);
try {
if (serverplayerentity != null) {
this.state = ServerLoginPacketListenerImpl.State.DELAY_ACCEPT;
this.delayedAcceptPlayer = entity;
} else {
this.server.getPlayerList().placeNewPlayer(this.connection, entity);
}
} catch (Exception exception) {
TranslatableComponent chatmessage = new TranslatableComponent("multiplayer.disconnect.invalid_player_data");
this.connection.send(new ClientboundDisconnectPacket(chatmessage));
this.connection.disconnect(chatmessage);
}
}
}
@ -189,10 +196,10 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle
throw new IllegalStateException("Protocol error");
}
this.secretKey = packetIn.getSecretKey(privatekey);
Cipher cipher = Crypt.getCipher(2, this.secretKey);
Cipher cipher1 = Crypt.getCipher(1, this.secretKey);
s = (new BigInteger(Crypt.digestData("", this.server.getKeyPair().getPublic(), this.secretKey))).toString(16);
SecretKey secretKey = packetIn.getSecretKey(privatekey);
Cipher cipher = Crypt.getCipher(2, secretKey);
Cipher cipher1 = Crypt.getCipher(1, secretKey);
s = (new BigInteger(Crypt.digestData("", this.server.getKeyPair().getPublic(), secretKey))).toString(16);
this.state = ServerLoginPacketListenerImpl.State.AUTHENTICATING;
this.connection.setEncryptionKey(cipher, cipher1);
} catch (CryptException cryptexception) {

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.network.status;
package io.izzel.arclight.common.mixin.core.network;
import com.mojang.authlib.GameProfile;
import io.izzel.arclight.common.mod.util.ArclightPingEvent;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.network.datasync;
package io.izzel.arclight.common.mixin.core.network;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.network.datasync.EntityDataManagerBridge;
@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(SynchedEntityData.class)
public abstract class EntityDataManagerMixin implements EntityDataManagerBridge {
public abstract class SynchedEntityDataMixin implements EntityDataManagerBridge {
// @formatter:off
@Shadow protected abstract <T> SynchedEntityData.DataItem<T> getItem(EntityDataAccessor<T> key);

View File

@ -1,51 +0,0 @@
package io.izzel.arclight.common.mixin.core.network.handshake.client;
import com.google.gson.Gson;
import com.mojang.authlib.properties.Property;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
import net.minecraftforge.fml.network.FMLNetworkConstants;
import net.minecraftforge.fml.network.NetworkHooks;
import org.spigotmc.SpigotConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Objects;
@Mixin(ClientIntentionPacket.class)
public class CHandshakePacketMixin {
// @formatter:off
@Shadow(remap = false) private String fmlVersion;
@Shadow public String hostName;
// @formatter:on
private static final String EXTRA_DATA = "extraData";
private static final Gson GSON = new Gson();
@Redirect(method = "read", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/FriendlyByteBuf;readUtf(I)Ljava/lang/String;"))
private String arclight$bungeeHostname(FriendlyByteBuf packetBuffer, int maxLength) {
return packetBuffer.readUtf(Short.MAX_VALUE);
}
@Inject(method = "read", cancellable = true, at = @At(value = "FIELD", shift = At.Shift.AFTER, remap = false, target = "Lnet/minecraft/network/protocol/handshake/ClientIntentionPacket;fmlVersion:Ljava/lang/String;"))
private void arclight$readFromProfile(FriendlyByteBuf buf, CallbackInfo ci) {
if (SpigotConfig.bungee && !Objects.equals(this.fmlVersion, FMLNetworkConstants.NETVERSION)) {
String[] split = this.hostName.split("\0");
if (split.length == 4) {
Property[] properties = GSON.fromJson(split[3], Property[].class);
for (Property property : properties) {
if (Objects.equals(property.getName(), EXTRA_DATA)) {
String extraData = property.getValue().replace("\1", "\0");
this.fmlVersion = NetworkHooks.getFMLVersion(split[0] + extraData);
}
}
}
}
ci.cancel();
}
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.network;
package io.izzel.arclight.common.mixin.core.network.protocol;
import io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge;
import io.izzel.arclight.common.bridge.server.MinecraftServerBridge;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.network.play.client;
package io.izzel.arclight.common.mixin.core.network.protocol.game;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.spongepowered.asm.mixin.Mixin;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.network.play.client;
package io.izzel.arclight.common.mixin.core.network.protocol.game;
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
import org.spongepowered.asm.mixin.Mixin;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.network.play.client;
package io.izzel.arclight.common.mixin.core.network.protocol.game;
import io.izzel.arclight.common.bridge.network.play.TimestampedPacket;
import net.minecraft.network.FriendlyByteBuf;
@ -13,7 +13,7 @@ public class CPlayerTryUseItemOnBlockPacketMixin implements TimestampedPacket {
public long timestamp;
@Inject(method = "read", at = @At("HEAD"))
@Inject(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN"))
private void arclight$read(FriendlyByteBuf buf, CallbackInfo ci) {
this.timestamp = System.currentTimeMillis();
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.network.play.client;
package io.izzel.arclight.common.mixin.core.network.protocol.game;
import io.izzel.arclight.common.bridge.network.play.TimestampedPacket;
import net.minecraft.network.FriendlyByteBuf;
@ -13,7 +13,7 @@ public class CPlayerTryUseItemPacketMixin implements TimestampedPacket {
public long timestamp;
@Inject(method = "read", at = @At("HEAD"))
@Inject(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN"))
private void arclight$read(FriendlyByteBuf buf, CallbackInfo ci) {
this.timestamp = System.currentTimeMillis();
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.network.play.server;
package io.izzel.arclight.common.mixin.core.network.protocol.game;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.chat.ComponentSerializer;

View File

@ -1,7 +1,7 @@
package io.izzel.arclight.common.mixin.core.network.play.server;
package io.izzel.arclight.common.mixin.core.network.protocol.game;
import io.izzel.arclight.common.bridge.world.border.WorldBorderBridge;
import net.minecraft.network.protocol.game.ClientboundSetBorderPacket;
import net.minecraft.network.protocol.game.ClientboundSetBorderCenterPacket;
import net.minecraft.world.level.border.WorldBorder;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientboundSetBorderPacket.class)
@Mixin(ClientboundSetBorderCenterPacket.class)
public class SWorldBorderPacketMixin {
// @formatter:off
@ -17,8 +17,8 @@ public class SWorldBorderPacketMixin {
@Shadow private double newCenterZ;
// @formatter:on
@Inject(method = "<init>(Lnet/minecraft/world/level/border/WorldBorder;Lnet/minecraft/network/protocol/game/ClientboundSetBorderPacket$Type;)V", at = @At("RETURN"))
private void arclight$nether(WorldBorder border, ClientboundSetBorderPacket.Type actionIn, CallbackInfo ci) {
@Inject(method = "<init>(Lnet/minecraft/world/level/border/WorldBorder;)V", at = @At("RETURN"))
private void arclight$nether(WorldBorder border, CallbackInfo ci) {
this.newCenterX = border.getCenterX() * (((WorldBorderBridge) border).bridge$getWorld().dimensionType().coordinateScale());
this.newCenterZ = border.getCenterZ() * (((WorldBorderBridge) border).bridge$getWorld().dimensionType().coordinateScale());
}

View File

@ -0,0 +1,44 @@
package io.izzel.arclight.common.mixin.core.network.protocol.handshake;
import com.google.gson.Gson;
import com.mojang.authlib.properties.Property;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
import net.minecraftforge.fmllegacy.network.FMLNetworkConstants;
import net.minecraftforge.fmllegacy.network.NetworkHooks;
import org.spigotmc.SpigotConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.Objects;
@Mixin(ClientIntentionPacket.class)
public class CHandshakePacketMixin {
private static final String EXTRA_DATA = "extraData";
private static final Gson GSON = new Gson();
@Redirect(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/FriendlyByteBuf;readUtf(I)Ljava/lang/String;"))
private String arclight$bungeeHostname(FriendlyByteBuf packetBuffer, int maxLength) {
return packetBuffer.readUtf(Short.MAX_VALUE);
}
@Redirect(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/fmllegacy/network/NetworkHooks;getFMLVersion(Ljava/lang/String;)Ljava/lang/String;"))
private String arclight$readFromProfile(String ip) {
String fmlVersion = NetworkHooks.getFMLVersion(ip);
if (SpigotConfig.bungee && !Objects.equals(fmlVersion, FMLNetworkConstants.NETVERSION)) {
String[] split = ip.split("\0");
if (split.length == 4) {
Property[] properties = GSON.fromJson(split[3], Property[].class);
for (Property property : properties) {
if (Objects.equals(property.getName(), EXTRA_DATA)) {
String extraData = property.getValue().replace("\1", "\0");
return NetworkHooks.getFMLVersion(split[0] + extraData);
}
}
}
}
return fmlVersion;
}
}

View File

@ -16,6 +16,7 @@ import joptsimple.OptionSet;
import net.minecraft.CrashReport;
import net.minecraft.ReportedException;
import net.minecraft.SharedConstants;
import net.minecraft.SystemReport;
import net.minecraft.Util;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
@ -23,6 +24,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.status.ServerStatus;
import net.minecraft.obfuscate.DontObfuscate;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerResources;
@ -36,7 +38,6 @@ import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.server.players.GameProfileCache;
import net.minecraft.util.Unit;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.util.profiling.SingleTickProfiler;
import net.minecraft.util.thread.ReentrantBlockableEventLoop;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.DataPackConfig;
@ -49,8 +50,8 @@ import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraft.world.level.storage.WorldData;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.world.StructureSpawnManager;
import net.minecraftforge.fml.BrandingControl;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import net.minecraftforge.fmllegacy.BrandingControl;
import net.minecraftforge.fmllegacy.server.ServerLifecycleHooks;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -97,31 +98,32 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
@Shadow protected abstract void updateStatusIcon(ServerStatus response);
@Shadow private volatile boolean running;
@Shadow private long lastOverloadWarning;
@Shadow @Final private static Logger LOGGER;
@Shadow private boolean delayProfilerStart;
@Shadow protected abstract void tickServer(BooleanSupplier hasTimeLeft);
@Shadow @Final static Logger LOGGER;
@Shadow public abstract void tickServer(BooleanSupplier hasTimeLeft);
@Shadow protected abstract boolean haveTime();
@Shadow private boolean mayHaveDelayedTasks;
@Shadow private long delayedTasksMaxNextTickTime;
@Shadow protected abstract void waitUntilNextTick();
@Shadow private volatile boolean isReady;
@Shadow protected abstract void onServerCrash(CrashReport report);
@Shadow public abstract CrashReport fillReport(CrashReport report);
@Shadow public abstract File getServerDirectory();
@Shadow private boolean stopped;
@Shadow protected abstract void stopServer();
@Shadow protected abstract void onServerExit();
@Shadow public abstract void stopServer();
@Shadow public abstract void onServerExit();
@Shadow public abstract Commands getCommands();
@Shadow protected abstract void startProfilerTick(@org.jetbrains.annotations.Nullable SingleTickProfiler p_240773_1_);
@Shadow private ProfilerFiller profiler;
@Shadow protected abstract void endProfilerTick(@org.jetbrains.annotations.Nullable SingleTickProfiler p_240795_1_);
@Shadow protected abstract void updateMobSpawningFlags();
@Shadow public abstract ServerLevel overworld();
@Shadow @Final public Map<ResourceKey<Level>, ServerLevel> levels;
@Shadow protected abstract void setupDebugLevel(WorldData p_240778_1_);
@Shadow protected WorldData worldData;
@Shadow private static void setInitialSpawn(ServerLevel p_240786_0_, ServerLevelData p_240786_1_, boolean hasBonusChest, boolean p_240786_3_, boolean p_240786_4_) { }
@Shadow(remap = false) @Deprecated public abstract void markWorldsDirty();
@Shadow private static void setInitialSpawn(ServerLevel p_177897_, ServerLevelData p_177898_, boolean p_177899_, boolean p_177900_) { }
@Shadow public abstract boolean isSpawningMonsters();
@Shadow public abstract boolean isSpawningAnimals();
@Shadow protected abstract void startMetricsRecordingTick();
@Shadow protected abstract void endMetricsRecordingTick();
@Shadow public abstract SystemReport fillSystemReport(SystemReport p_177936_);
// @formatter:on
public MinecraftServerMixin(String name) {
@ -211,9 +213,7 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
currentTick = (int) (System.currentTimeMillis() / 50);
this.nextTickTime += 50L;
SingleTickProfiler longtickdetector = SingleTickProfiler.createTickProfiler("Server");
this.startProfilerTick(longtickdetector);
this.profiler.startTick();
this.startMetricsRecordingTick();
this.profiler.push("tick");
this.tickServer(this::haveTime);
this.profiler.popPush("nextTickWait");
@ -221,8 +221,7 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
this.delayedTasksMaxNextTickTime = Math.max(Util.getMillis() + 50L, this.nextTickTime);
this.waitUntilNextTick();
this.profiler.pop();
this.profiler.endTick();
this.endProfilerTick(longtickdetector);
this.endMetricsRecordingTick();
this.isReady = true;
}
ServerLifecycleHooks.handleServerStopping((MinecraftServer) (Object) this);
@ -240,11 +239,12 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
CrashReport crashreport;
if (throwable1 instanceof ReportedException) {
crashreport = this.fillReport(((ReportedException) throwable1).getReport());
crashreport = ((ReportedException) throwable1).getReport();
} else {
crashreport = this.fillReport(new CrashReport("Exception in server tick loop", throwable1));
crashreport = new CrashReport("Exception in server tick loop", throwable1);
}
this.fillSystemReport(crashreport.getSystemReport());
File file1 = new File(new File(this.getServerDirectory(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");
if (crashreport.saveToFile(file1)) {
LOGGER.error("This crash report has been saved to: {}", file1.getAbsolutePath());
@ -362,7 +362,7 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
for (ServerLevel serverWorld : this.levels.values()) {
if (((WorldBridge) serverWorld).bridge$getWorld().getKeepSpawnInMemory()) {
ForcedChunksSavedData forcedchunkssavedata = serverWorld.getDataStorage().get(ForcedChunksSavedData::new, "chunks");
ForcedChunksSavedData forcedchunkssavedata = serverWorld.getDataStorage().get(ForcedChunksSavedData::load, "chunks");
if (forcedchunkssavedata != null) {
LongIterator longiterator = forcedchunkssavedata.getChunks().iterator();
@ -396,7 +396,7 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
worldborder.applySettings(worldInfo.getWorldBorder());
if (!worldInfo.isInitialized()) {
try {
setInitialSpawn(serverWorld, worldInfo, generatorSettings.generateBonusChest(), flag, true);
setInitialSpawn(serverWorld, worldInfo, generatorSettings.generateBonusChest(), flag);
worldInfo.setInitialized(true);
if (flag) {
this.setupDebugLevel(this.worldData);
@ -436,7 +436,7 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
this.executeModerately();
ForcedChunksSavedData forcedchunkssavedata = serverWorld.getDataStorage().get(ForcedChunksSavedData::new, "chunks");
ForcedChunksSavedData forcedchunkssavedata = serverWorld.getDataStorage().get(ForcedChunksSavedData::load, "chunks");
if (forcedchunkssavedata != null) {
LongIterator longiterator = forcedchunkssavedata.getChunks().iterator();
@ -450,7 +450,8 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
this.executeModerately();
listener.stop();
serverchunkprovider.getLightEngine().setTaskPerBatch(5);
this.updateMobSpawningFlags();
// this.updateMobSpawningFlags();
serverWorld.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals());
this.forceTicks = false;
}
@ -470,6 +471,7 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
* @author IzzelAliz
* @reason our branding, no one should fuck this up
*/
@DontObfuscate
@Overwrite
public String getServerModName() {
return BrandingControl.getServerBranding() + " arclight";

View File

@ -1,21 +1,21 @@
package io.izzel.arclight.common.mixin.core.scoreboard;
package io.izzel.arclight.common.mixin.core.server;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import net.minecraft.network.protocol.Packet;
import net.minecraft.server.ServerScoreboard;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.List;
import java.util.stream.Collectors;
import net.minecraft.network.protocol.Packet;
import net.minecraft.server.ServerScoreboard;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
@Mixin(ServerScoreboard.class)
public class ServerScoreboardMixin {
@Redirect(method = "addObjective", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;getPlayers()Ljava/util/List;"))
@Redirect(method = "startTrackingObjective", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;getPlayers()Ljava/util/List;"))
private List<ServerPlayer> arclight$filterAdd(PlayerList playerList) {
return filterPlayer(playerList.getPlayers());
}

View File

@ -35,10 +35,8 @@ import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.DemoMode;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
import net.minecraft.server.players.IpBanList;
import net.minecraft.server.players.IpBanListEntry;
@ -61,6 +59,7 @@ import net.minecraft.world.level.storage.LevelData;
import net.minecraft.world.level.storage.LevelResource;
import net.minecraft.world.level.storage.PlayerDataStorage;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.fmllegacy.hooks.BasicEventHooks;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.CraftServer;
@ -123,7 +122,6 @@ public abstract class PlayerListMixin implements PlayerListBridge {
@Shadow public abstract void sendAllPlayerInfo(ServerPlayer playerIn);
@Shadow public abstract void broadcastMessage(Component p_232641_1_, ChatType p_232641_2_, UUID p_232641_3_);
@Shadow @Nullable public abstract ServerPlayer getPlayer(UUID playerUUID);
@Shadow protected abstract void updatePlayerGameMode(ServerPlayer target, @org.jetbrains.annotations.Nullable ServerPlayer source, ServerLevel worldIn);
// @formatter:on
private CraftServer cserver;
@ -155,9 +153,9 @@ public abstract class PlayerListMixin implements PlayerListBridge {
return ((WorldBridge) playerIn.getLevel()).bridge$spigotConfig().viewDistance;
}
@Eject(method = "initializeConnectionToPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;func_232641_a_(Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/util/text/ChatType;Ljava/util/UUID;)V"))
@Eject(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"))
private void arclight$playerJoin(PlayerList playerList, Component component, ChatType chatType, UUID uuid, CallbackInfo ci, Connection netManager, ServerPlayer playerIn) {
PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(this.cserver.getPlayer(playerIn), CraftChatMessage.fromComponent(component));
PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), CraftChatMessage.fromComponent(component));
this.players.add(playerIn);
this.playersByUUID.put(playerIn.getUUID(), playerIn);
this.cserver.getPluginManager().callEvent(playerJoinEvent);
@ -193,7 +191,7 @@ public abstract class PlayerListMixin implements PlayerListBridge {
if (playerIn.inventoryMenu != playerIn.containerMenu) {
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().closeInventory();
}
PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(playerIn), "\u00A7e" + playerIn.getScoreboardName() + " left the game");
PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), "\u00A7e" + playerIn.getScoreboardName() + " left the game");
cserver.getPluginManager().callEvent(playerQuitEvent);
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
playerIn.doTick();
@ -214,7 +212,7 @@ public abstract class PlayerListMixin implements PlayerListBridge {
this.save(entityplayer);
entityplayer.connection.disconnect(new TranslatableComponent("multiplayer.disconnect.duplicate_login"));
}
ServerPlayer entity = new ServerPlayer(this.server, this.server.getLevel(Level.OVERWORLD), gameProfile, new ServerPlayerGameMode(this.server.getLevel(Level.OVERWORLD)));
ServerPlayer entity = new ServerPlayer(this.server, this.server.getLevel(Level.OVERWORLD), gameProfile);
Player player = ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity();
String hostname = handler == null ? "" : ((ServerLoginNetHandlerBridge) handler).bridge$getHostname();
@ -305,7 +303,7 @@ public abstract class PlayerListMixin implements PlayerListBridge {
pos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(spawnWorld);
location = new Location(((WorldBridge) spawnWorld).bridge$getWorld(), pos.getX() + 0.5f, pos.getY() + 0.1f, pos.getZ() + 0.5f);
}
Player respawnPlayer = this.cserver.getPlayer(playerIn);
Player respawnPlayer = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity();
PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn && !flag3, flag3);
this.cserver.getPluginManager().callEvent(respawnEvent);
if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
@ -328,7 +326,7 @@ public abstract class PlayerListMixin implements PlayerListBridge {
playerIn.connection.send(new ClientboundRespawnPacket(serverWorld.dimensionType(), serverWorld.dimension(), BiomeManager.obfuscateSeed(serverWorld.getSeed()), playerIn.gameMode.getGameModeForPlayer(), playerIn.gameMode.getPreviousGameModeForPlayer(), serverWorld.isDebug(), serverWorld.isFlat(), flag));
playerIn.connection.send(new ClientboundSetChunkCacheRadiusPacket(((WorldBridge) serverWorld).bridge$spigotConfig().viewDistance));
playerIn.setLevel(serverWorld);
((ServerPlayNetHandlerBridge) playerIn.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), playerIn.getX(), playerIn.getY(), playerIn.getZ(), playerIn.yRot, playerIn.xRot));
((ServerPlayNetHandlerBridge) playerIn.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), playerIn.getX(), playerIn.getY(), playerIn.getZ(), playerIn.getYRot(), playerIn.getXRot()));
playerIn.setShiftKeyDown(false);
playerIn.connection.send(new ClientboundSetDefaultSpawnPositionPacket(serverWorld.getSharedSpawnPos(), serverWorld.getSharedSpawnAngle()));
playerIn.connection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
@ -341,7 +339,7 @@ public abstract class PlayerListMixin implements PlayerListBridge {
this.playersByUUID.put(playerIn.getUUID(), playerIn);
}
playerIn.setHealth(playerIn.getHealth());
net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerChangedDimensionEvent(playerIn, ((CraftWorld) fromWorld).getHandle().dimension, serverWorld.dimension);
BasicEventHooks.firePlayerChangedDimensionEvent(playerIn, ((CraftWorld) fromWorld).getHandle().dimension, serverWorld.dimension);
if (flag3) {
playerIn.connection.send(new ClientboundSoundPacket(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f));
}
@ -421,7 +419,7 @@ public abstract class PlayerListMixin implements PlayerListBridge {
pos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(spawnWorld);
location = new Location(((WorldBridge) spawnWorld).bridge$getWorld(), pos.getX() + 0.5f, pos.getY() + 0.1f, pos.getZ() + 0.5f);
}
Player respawnPlayer = this.cserver.getPlayer(playerIn);
Player respawnPlayer = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity();
PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn && !flag3, flag3);
this.cserver.getPluginManager().callEvent(respawnEvent);
if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
@ -436,14 +434,8 @@ public abstract class PlayerListMixin implements PlayerListBridge {
}
ServerLevel serverWorld = ((CraftWorld) location.getWorld()).getHandle();
ServerPlayerGameMode playerinteractionmanager;
if (this.server.isDemo()) {
playerinteractionmanager = new DemoMode(serverWorld);
} else {
playerinteractionmanager = new ServerPlayerGameMode(serverWorld);
}
ServerPlayer serverplayerentity = new ServerPlayer(this.server, serverWorld, playerIn.getGameProfile(), playerinteractionmanager);
ServerPlayer serverplayerentity = new ServerPlayer(this.server, serverWorld, playerIn.getGameProfile());
// Forward to new player instance
((InternalEntityBridge) playerIn).internal$getBukkitEntity().setHandle(serverplayerentity);
@ -455,7 +447,7 @@ public abstract class PlayerListMixin implements PlayerListBridge {
serverplayerentity.connection = playerIn.connection;
serverplayerentity.restoreFrom(playerIn, conqueredEnd);
if (!conqueredEnd) { // keep inventory here since inventory dropped at ServerPlayerEntity#onDeath
serverplayerentity.inventory.replaceWith(playerIn.inventory);
serverplayerentity.getInventory().replaceWith(playerIn.getInventory());
}
playerIn.remove(false); // Forge: clone event had a chance to see old data, now discard it
serverplayerentity.setId(playerIn.getId());
@ -468,8 +460,7 @@ public abstract class PlayerListMixin implements PlayerListBridge {
serverplayerentity.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
serverplayerentity.connection.resetPosition();
this.updatePlayerGameMode(serverplayerentity, playerIn, serverWorld);
while (avoidSuffocation && !serverWorld.noCollision(serverplayerentity) && serverplayerentity.getY() < 256.0D) {
while (avoidSuffocation && !serverWorld.noCollision(serverplayerentity) && serverplayerentity.getY() < serverWorld.getMaxBuildHeight()) {
serverplayerentity.setPos(serverplayerentity.getX(), serverplayerentity.getY() + 1.0D, serverplayerentity.getZ());
}
@ -477,7 +468,7 @@ public abstract class PlayerListMixin implements PlayerListBridge {
serverplayerentity.connection.send(new ClientboundRespawnPacket(serverplayerentity.level.dimensionType(), serverplayerentity.level.dimension(), BiomeManager.obfuscateSeed(serverplayerentity.getLevel().getSeed()), serverplayerentity.gameMode.getGameModeForPlayer(), serverplayerentity.gameMode.getPreviousGameModeForPlayer(), serverplayerentity.getLevel().isDebug(), serverplayerentity.getLevel().isFlat(), conqueredEnd));
serverplayerentity.connection.send(new ClientboundSetChunkCacheRadiusPacket(((WorldBridge) serverWorld).bridge$spigotConfig().viewDistance));
serverplayerentity.setLevel(serverWorld);
((ServerPlayNetHandlerBridge) serverplayerentity.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), serverplayerentity.getX(), serverplayerentity.getY(), serverplayerentity.getZ(), serverplayerentity.yRot, serverplayerentity.xRot));
((ServerPlayNetHandlerBridge) serverplayerentity.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), serverplayerentity.getX(), serverplayerentity.getY(), serverplayerentity.getZ(), serverplayerentity.getYRot(), serverplayerentity.getXRot()));
serverplayerentity.setShiftKeyDown(false);
serverplayerentity.connection.send(new ClientboundSetDefaultSpawnPositionPacket(serverWorld.getSharedSpawnPos(), serverWorld.getSharedSpawnAngle()));
serverplayerentity.connection.send(new ClientboundChangeDifficultyPacket(iworldinfo.getDifficulty(), iworldinfo.isDifficultyLocked()));
@ -489,9 +480,9 @@ public abstract class PlayerListMixin implements PlayerListBridge {
this.addPlayer(serverplayerentity);
this.playersByUUID.put(serverplayerentity.getUUID(), serverplayerentity);
}
serverplayerentity.initMenu();
serverplayerentity.initInventoryMenu();
serverplayerentity.setHealth(serverplayerentity.getHealth());
net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerRespawnEvent(serverplayerentity, conqueredEnd);
BasicEventHooks.firePlayerRespawnEvent(serverplayerentity, conqueredEnd);
if (flag2) {
serverplayerentity.connection.send(new ClientboundSoundPacket(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 1.0F, 1.0F));
}
@ -526,7 +517,7 @@ public abstract class PlayerListMixin implements PlayerListBridge {
}
}
@Inject(method = "sendPlayerPermissionLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getCommands()Lnet/minecraft/commands/Commands;"))
@Inject(method = "sendPlayerPermissionLevel(Lnet/minecraft/server/level/ServerPlayer;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getCommands()Lnet/minecraft/commands/Commands;"))
private void arclight$calculatePerms(ServerPlayer player, int permLevel, CallbackInfo ci) {
((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().recalculatePermissions();
}
@ -553,11 +544,6 @@ public abstract class PlayerListMixin implements PlayerListBridge {
this.sendMessage(components);
}
@Redirect(method = "broadcastMessage", at = @At(value = "NEW", target = "net/minecraft/network/protocol/game/ClientboundChatPacket"))
private ClientboundChatPacket arclight$addWebLinks(Component message, ChatType type, UUID uuid) {
return new ClientboundChatPacket(CraftChatMessage.fixComponent(message), type, uuid);
}
public ServerStatsCounter getStatisticManager(ServerPlayer entityhuman) {
ServerStatsCounter serverstatisticmanager = entityhuman.getStats();
return serverstatisticmanager == null ? this.getStatisticManager(entityhuman.getUUID(), entityhuman.getName().getString()) : serverstatisticmanager;

View File

@ -30,13 +30,17 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.common.ForgeHooks;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.event.Event;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
@ -48,11 +52,11 @@ import java.util.List;
import java.util.Objects;
@Mixin(ServerPlayerGameMode.class)
public abstract class PlayerInteractionManagerMixin implements PlayerInteractionManagerBridge {
public abstract class ServerPlayerGameModeMixin implements PlayerInteractionManagerBridge {
// @formatter:off
@Shadow public ServerLevel level;
@Shadow public ServerPlayer player;
@Shadow protected ServerLevel level;
@Shadow @Final protected ServerPlayer player;
@Shadow public abstract boolean isCreative();
@Shadow private GameType gameModeForPlayer;
@Shadow private int destroyProgressStart;
@ -69,6 +73,15 @@ public abstract class PlayerInteractionManagerMixin implements PlayerInteraction
public boolean interactResult = false;
public boolean firedInteract = false;
@Inject(method = "changeGameModeForPlayer", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayerGameMode;setGameModeForPlayer(Lnet/minecraft/world/level/GameType;Lnet/minecraft/world/level/GameType;)V"))
private void arclight$gameModeEvent(GameType gameType, CallbackInfoReturnable<Boolean> cir) {
PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(((ServerPlayerEntityBridge) player).bridge$getBukkitEntity(), GameMode.getByValue(gameType.getId()));
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
cir.setReturnValue(false);
}
}
/**
* @author IzzelAliz
* @reason
@ -93,7 +106,7 @@ public abstract class PlayerInteractionManagerMixin implements PlayerInteraction
this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, false, "too high"));
} else if (action == ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK) {
if (!this.level.mayInteract(this.player, blockPos)) {
CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockPos, direction, this.player.inventory.getSelected(), InteractionHand.MAIN_HAND);
CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockPos, direction, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, false, "may not interact"));
BlockEntity tileentity = this.level.getBlockEntity(blockPos);
if (tileentity != null) {
@ -101,7 +114,7 @@ public abstract class PlayerInteractionManagerMixin implements PlayerInteraction
}
return;
}
PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockPos, direction, this.player.inventory.getSelected(), InteractionHand.MAIN_HAND);
PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockPos, direction, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
if (event.isCancelled()) {
this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, blockPos));
BlockEntity tileentity2 = this.level.getBlockEntity(blockPos);
@ -130,7 +143,7 @@ public abstract class PlayerInteractionManagerMixin implements PlayerInteraction
} else if (data.getBlock() instanceof TrapDoorBlock) {
this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, blockPos));
}
} else if (!iblockdata.isAir(level, blockPos)) {
} else if (!iblockdata.isAir()) {
if (forgeEvent.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY) {
iblockdata.attack(this.level, blockPos, this.player);
}
@ -142,7 +155,7 @@ public abstract class PlayerInteractionManagerMixin implements PlayerInteraction
}
return;
}
BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, blockPos.getX(), blockPos.getY(), blockPos.getZ(), this.player.inventory.getSelected(), f >= 1.0f);
BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, blockPos.getX(), blockPos.getY(), blockPos.getZ(), this.player.getInventory().getSelected(), f >= 1.0f);
if (blockEvent.isCancelled()) {
this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, blockPos));
return;
@ -150,7 +163,7 @@ public abstract class PlayerInteractionManagerMixin implements PlayerInteraction
if (blockEvent.getInstaBreak()) {
f = 2.0f;
}
if (!iblockdata.isAir(level, blockPos) && f >= 1.0f) {
if (!iblockdata.isAir() && f >= 1.0f) {
this.destroyAndAck(blockPos, action, "insta mine");
} else {
if (this.isDestroyingBlock) {

View File

@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(StatsCounter.class)
public abstract class StatisticsManagerMixin {
public abstract class StatisticsCounterMixin {
// @formatter:off
@Shadow public abstract int getValue(Stat<?> stat);

View File

@ -1,6 +1,10 @@
package io.izzel.arclight.common.mixin.core.inventory;
package io.izzel.arclight.common.mixin.core.world;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import net.minecraft.world.CompoundContainer;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.entity.HumanEntity;
@ -11,13 +15,9 @@ import org.spongepowered.asm.mixin.Shadow;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.world.CompoundContainer;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
@Mixin(CompoundContainer.class)
public abstract class DoubleSidedInventoryMixin implements IInventoryBridge, Container {
public abstract class CompoundContainerMixin implements IInventoryBridge, Container {
@Shadow @Final public Container container1;
@Shadow @Final public Container container2;

View File

@ -1,6 +1,9 @@
package io.izzel.arclight.common.mixin.core.inventory;
package io.izzel.arclight.common.mixin.core.world;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.entity.HumanEntity;
@ -9,12 +12,9 @@ import org.spongepowered.asm.mixin.Mixin;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
@Mixin(Container.class)
public interface IInventoryMixin extends IInventoryBridge {
public interface ContainerMixin extends IInventoryBridge {
@Override
default List<ItemStack> getContents() {

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory;
package io.izzel.arclight.common.mixin.core.world;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import net.minecraft.core.NonNullList;
@ -18,7 +18,7 @@ import java.util.ArrayList;
import java.util.List;
@Mixin(SimpleContainer.class)
public abstract class InventoryMixin implements Container, IInventoryBridge {
public abstract class SimpleContainerMixin implements Container, IInventoryBridge {
// @formatter:off
@Shadow @Final public NonNullList<ItemStack> items;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.potion;
package io.izzel.arclight.common.mixin.core.world.effect;
import io.izzel.arclight.common.bridge.entity.LivingEntityBridge;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MobEffect.class)
public class EffectMixin {
public class MobEffectMixin {
@Inject(method = "applyEffectTick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/entity/LivingEntity;heal(F)V"))
public void arclight$healReason1(LivingEntity livingEntity, int amplifier, CallbackInfo ci) {

View File

@ -203,6 +203,8 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge,
@Shadow protected abstract void unsetRemoved();
@Shadow public abstract double getY(double p_20228_);
@Shadow public abstract void gameEvent(GameEvent p_146853_, @org.jetbrains.annotations.Nullable Entity p_146854_);
@Shadow public abstract void setTicksFrozen(int p_146918_);
@Shadow public abstract void setSharedFlagOnFire(boolean p_146869_);
// @formatter:on
private static final int CURRENT_LEVEL = 2;

View File

@ -187,7 +187,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt
public boolean forceDrops;
public CraftAttributeMap craftAttributes;
public boolean collides;
public boolean canPickUpLoot;
public boolean bukkitPickUpLoot;
public Set<UUID> collidableExemptions = new HashSet<>();
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setHealth(F)V"))
@ -396,7 +396,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt
@Override
public boolean bridge$canPickUpLoot() {
return canPickUpLoot;
return bukkitPickUpLoot;
}
@Override

View File

@ -78,7 +78,7 @@ public abstract class MobMixin extends LivingEntityMixin implements MobEntityBri
@Inject(method = "setCanPickUpLoot", at = @At("HEAD"))
public void arclight$setPickupLoot(boolean canPickup, CallbackInfo ci) {
super.canPickUpLoot = canPickup;
super.bukkitPickUpLoot = canPickup;
}
/**
@ -87,7 +87,7 @@ public abstract class MobMixin extends LivingEntityMixin implements MobEntityBri
*/
@Overwrite
public boolean canPickUpLoot() {
return super.canPickUpLoot;
return super.bukkitPickUpLoot;
}
@Inject(method = "<init>", at = @At("RETURN"))

View File

@ -124,6 +124,8 @@ public abstract class PlayerMixin extends LivingEntityMixin implements PlayerEnt
@Shadow public abstract Either<net.minecraft.world.entity.player.Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos at);
@Shadow public int sleepCounter;
@Shadow public abstract GameProfile getGameProfile();
@Shadow public abstract Inventory getInventory();
@Shadow public abstract Abilities getAbilities();
// @formatter:on
public boolean fauxSleeping;

View File

@ -10,15 +10,13 @@ import io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge;
import io.izzel.arclight.common.bridge.util.FoodStatsBridge;
import io.izzel.arclight.common.bridge.world.TeleporterBridge;
import io.izzel.arclight.common.bridge.world.WorldBridge;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import io.izzel.arclight.common.mod.util.BlackholeNetHandler;
import io.izzel.arclight.common.mod.server.block.ChestBlockDoubleInventoryHacks;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import net.minecraft.BlockUtil;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
@ -26,12 +24,11 @@ import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
import net.minecraft.network.protocol.game.ClientboundHorseScreenOpenPacket;
import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerCombatPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerCombatKillPacket;
import net.minecraft.network.protocol.game.ClientboundRespawnPacket;
import net.minecraft.network.protocol.game.ClientboundSetHealthPacket;
import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket;
@ -64,7 +61,6 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodData;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.HorseInventoryMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
@ -80,17 +76,16 @@ import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.Team;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.ITeleporter;
import net.minecraftforge.fml.hooks.BasicEventHooks;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import net.minecraftforge.fmllegacy.hooks.BasicEventHooks;
import net.minecraftforge.fmllegacy.server.ServerLifecycleHooks;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.WeatherType;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.CraftWorld;
import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.craftbukkit.v.entity.CraftPlayer;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.craftbukkit.v.event.CraftPortalEvent;
@ -99,10 +94,9 @@ import org.bukkit.craftbukkit.v.scoreboard.CraftScoreboardManager;
import org.bukkit.craftbukkit.v.util.CraftChatMessage;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChangedMainHandEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerLocaleChangeEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
@ -121,7 +115,6 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
@ -130,7 +123,7 @@ import java.util.UUID;
import java.util.function.Consumer;
@Mixin(ServerPlayer.class)
public abstract class ServerPlayerEntityMixin extends PlayerMixin implements ServerPlayerEntityBridge {
public abstract class ServerPlayerMixin extends PlayerMixin implements ServerPlayerEntityBridge {
// @formatter:off
@Shadow @Final public MinecraftServer server;
@ -165,6 +158,9 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
@Shadow protected abstract boolean bedBlocked(BlockPos p_241156_1_, Direction p_241156_2_);
@Shadow protected abstract boolean bedInRange(BlockPos p_241147_1_, Direction p_241147_2_);
@Shadow public abstract void sendMessage(Component component, UUID senderUUID);
@Shadow public abstract void setLevel(ServerLevel p_143426_);
@Shadow(remap = false) private boolean hasTabListName;
@Shadow(remap = false) private Component tabListDisplayName;
// @formatter:on
public String displayName;
@ -189,12 +185,9 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
@Inject(method = "<init>", at = @At("RETURN"))
public void arclight$init(CallbackInfo ci) {
this.displayName = this.getGameProfile() != null ? getScoreboardName() : "~FakePlayer~";
this.canPickUpLoot = true;
this.bukkitPickUpLoot = true;
this.maxHealthCache = this.getMaxHealth();
this.arclight$initialized = true;
if ((Object) this instanceof FakePlayer) {
this.connection = new BlackholeNetHandler(this.getServer(), (ServerPlayer) (Object) this);
}
}
@Override
@ -245,7 +238,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
}
}
@Redirect(method = "addAdditionalSaveData", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hasOnePlayerPassenger()Z"))
@Redirect(method = "addAdditionalSaveData", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hasExactlyOnePlayerPassenger()Z"))
private boolean arclight$nonPersistVehicle(Entity entity) {
Entity entity1 = this.getVehicle();
boolean persistVehicle = true;
@ -258,7 +251,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
}
}
}
return persistVehicle && entity.hasOnePlayerPassenger();
return persistVehicle && entity.hasExactlyOnePlayerPassenger();
}
@Inject(method = "addAdditionalSaveData", at = @At("RETURN"))
@ -266,9 +259,8 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
this.getBukkitEntity().setExtraData(compound);
}
@Override
public void setLevel(Level world) {
super.setLevel(world);
public void spawnIn(Level world) {
this.level = world;
if (world == null) {
this.revive();
Vec3 position = null;
@ -320,16 +312,16 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
if (net.minecraftforge.common.ForgeHooks.onLivingDeath((ServerPlayer) (Object) this, damagesource))
return;
boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
if (this.removed) {
if (this.isRemoved()) {
return;
}
boolean keepInventory = this.level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator();
Inventory copyInv;
if (keepInventory) {
copyInv = this.inventory;
copyInv = this.getInventory();
} else {
copyInv = new Inventory((ServerPlayer) (Object) this);
copyInv.replaceWith(this.inventory);
copyInv.replaceWith(this.getInventory());
}
this.dropAllDeathLoot(damagesource);
@ -344,7 +336,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
}
}
if (!keepInventory) {
this.inventory.replaceWith(copyInv);
this.getInventory().replaceWith(copyInv);
}
PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent((ServerPlayer) (Object) this, loot, deathmessage, keepInventory);
if (this.containerMenu != this.inventoryMenu) {
@ -358,15 +350,15 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
} else {
itextcomponent = CraftChatMessage.fromStringOrNull(deathMessage);
}
this.connection.send(new ClientboundPlayerCombatPacket(this.getCombatTracker(), ClientboundPlayerCombatPacket.Event.ENTITY_DIED, itextcomponent), (p_212356_2_) -> {
if (!p_212356_2_.isSuccess()) {
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), itextcomponent), (future) -> {
if (!future.isSuccess()) {
int i = 256;
String s = itextcomponent.getString(256);
Component itextcomponent1 = new TranslatableComponent("death.attack.message_too_long", (new TextComponent(s)).withStyle(ChatFormatting.YELLOW));
Component itextcomponent2 = (new TranslatableComponent("death.attack.even_more_magic", this.getDisplayName())).withStyle((p_212357_1_) -> {
return p_212357_1_.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, itextcomponent1));
});
this.connection.send(new ClientboundPlayerCombatPacket(this.getCombatTracker(), ClientboundPlayerCombatPacket.Event.ENTITY_DIED, itextcomponent2));
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), itextcomponent2));
}
});
@ -381,7 +373,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
this.server.getPlayerList().broadcastMessage(itextcomponent, ChatType.SYSTEM, Util.NIL_UUID);
}
} else {
this.connection.send(new ClientboundPlayerCombatPacket(this.getCombatTracker(), ClientboundPlayerCombatPacket.Event.ENTITY_DIED));
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), TextComponent.EMPTY));
}
this.removeEntitiesOnShoulder();
@ -392,7 +384,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
this.dropExperience();
if (!event.getKeepInventory()) {
this.inventory.clearContent();
this.getInventory().clearContent();
}
this.setCamera((ServerPlayer) (Object) this);
((CraftScoreboardManager) Bukkit.getScoreboardManager()).getScoreboardScores(ObjectiveCriteria.DEATH_COUNT, this.getScoreboardName(), Score::increment);
@ -409,7 +401,8 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
this.resetStat(Stats.CUSTOM.get(Stats.TIME_SINCE_DEATH));
this.resetStat(Stats.CUSTOM.get(Stats.TIME_SINCE_REST));
this.clearFire();
this.setSharedFlag(0, false);
this.setTicksFrozen(0);
this.setSharedFlagOnFire(false);
this.getCombatTracker().recheckStatus();
}
@ -549,7 +542,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
}
this.gameMode.setLevel(exitWorld[0]);
this.connection.send(new ClientboundPlayerAbilitiesPacket(this.abilities));
this.connection.send(new ClientboundPlayerAbilitiesPacket(this.getAbilities()));
playerlist.sendLevelInfo((ServerPlayer) (Object) this, exitWorld[0]);
playerlist.sendAllPlayerInfo((ServerPlayer) (Object) this);
@ -593,7 +586,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
Direction.Axis enumdirection_enumaxis = this.level.getBlockState(this.portalEntrancePos).getOptionalValue(NetherPortalBlock.AXIS).orElse(Direction.Axis.X);
Optional<BlockUtil.FoundRectangle> optional1 = ((TeleporterBridge) worldserver.getPortalForcer()).bridge$createPortal(blockposition, enumdirection_enumaxis, (ServerPlayer) (Object) this, createRadius);
if (!optional1.isPresent()) {
LOGGER.error("Unable to create a portal, likely target out of worldborder");
// LOGGER.error("Unable to create a portal, likely target out of worldborder");
}
return optional1;
}
@ -652,8 +645,26 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
}
@Inject(method = "stopSleepInBed", cancellable = true, at = @At(value = "HEAD"))
private void arclight$wakeupOutBed(boolean p_225652_1_, boolean p_225652_2_, CallbackInfo ci) {
if (!this.isSleeping()) ci.cancel();
private void arclight$wakeupOutBed(boolean flag, boolean flag1, CallbackInfo ci) {
if (!this.isSleeping()) {
ci.cancel();
return;
}
CraftPlayer player = this.getBukkitEntity();
BlockPos bedPosition = this.getSleepingPos().orElse(null);
org.bukkit.block.Block bed;
if (bedPosition != null) {
bed = CraftBlock.at(this.level, bedPosition);
} else {
bed = player.getLocation().getBlock();
}
PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed, true);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
ci.cancel();
}
}
public int nextContainerCounter() {
@ -687,7 +698,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
@Overwrite
public void openHorseInventory(final AbstractHorse entityhorseabstract, final Container iinventory) {
this.nextContainerCounter();
AbstractContainerMenu container = new HorseInventoryMenu(this.containerCounter, this.inventory, iinventory, entityhorseabstract);
AbstractContainerMenu container = new HorseInventoryMenu(this.containerCounter, this.getInventory(), iinventory, entityhorseabstract);
((ContainerBridge) container).bridge$setTitle(entityhorseabstract.getDisplayName());
container = CraftEventFactory.callInventoryOpenEvent((ServerPlayer) (Object) this, container);
if (container == null) {
@ -698,19 +709,10 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
this.closeContainer();
}
this.connection.send(new ClientboundHorseScreenOpenPacket(this.containerCounter, iinventory.getContainerSize(), entityhorseabstract.getId()));
(this.containerMenu = container).addSlotListener((ServerPlayer) (Object) this);
this.containerMenu = container;
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open((ServerPlayer) (Object) this, this.containerMenu));
}
@Inject(method = "refreshContainer", at = @At("RETURN"))
private void arclight$sendExtra(AbstractContainerMenu container, NonNullList<ItemStack> itemsList, CallbackInfo ci) {
ArclightCaptures.captureContainerOwner((ServerPlayer) (Object) this);
if (EnumSet.of(InventoryType.CRAFTING, InventoryType.WORKBENCH).contains(((ContainerBridge) container).bridge$getBukkitView().getType())) {
this.connection.send(new ClientboundContainerSetSlotPacket(container.containerId, 0, container.getSlot(0).getItem()));
}
ArclightCaptures.resetContainerOwner();
}
@Inject(method = "doCloseContainer", at = @At("HEAD"))
private void arclight$invClose(CallbackInfo ci) {
if (this.containerMenu != this.inventoryMenu) {
@ -749,20 +751,6 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
this.sendMessage(component, uuid == null ? Util.NIL_UUID : uuid);
}
@Inject(method = "setGameMode", cancellable = true, at = @At("HEAD"))
private void arclight$gameModeChange(GameType gameType, CallbackInfo ci) {
if (gameType == this.gameMode.getGameModeForPlayer()) {
ci.cancel();
return;
}
PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(getBukkitEntity(), GameMode.getByValue(gameType.getId()));
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
ci.cancel();
}
}
@Inject(method = "updateOptions", at = @At("HEAD"))
private void arclight$settingChange(ServerboundClientInformationPacket packetIn, CallbackInfo ci) {
if (this.getMainArm() != packetIn.getMainHand()) {
@ -789,10 +777,17 @@ public abstract class ServerPlayerEntityMixin extends PlayerMixin implements Ser
@Overwrite
@Nullable
public Component getTabListDisplayName() {
return listName;
if (this.listName != null) {
return this.listName;
}
if (!this.hasTabListName) {
this.tabListDisplayName = net.minecraftforge.event.ForgeEventFactory.getPlayerTabListDisplayName((ServerPlayer) (Object) this);
this.hasTabListName = true;
}
return tabListDisplayName;
}
@Inject(method = "teleportTo", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/level/ServerPlayer;stopRiding()V"))
@Inject(method = "teleportTo(Lnet/minecraft/server/level/ServerLevel;DDDFF)V", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/level/ServerPlayer;stopRiding()V"))
private void arclight$handleBy(ServerLevel world, double x, double y, double z, float yaw, float pitch, CallbackInfo ci) {
PlayerTeleportEvent.TeleportCause cause = arclight$cause == null ? PlayerTeleportEvent.TeleportCause.UNKNOWN : arclight$cause;
arclight$cause = null;

View File

@ -0,0 +1,415 @@
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge;
import io.izzel.arclight.common.bridge.inventory.container.SlotBridge;
import io.izzel.arclight.common.mod.server.ArclightContainer;
import net.minecraft.core.NonNullList;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.SlotAccess;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ClickAction;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.ContainerSynchronizer;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v.inventory.CraftInventory;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@Mixin(AbstractContainerMenu.class)
public abstract class AbstractContainerMenuMixin implements ContainerBridge {
// @formatter:off
@Shadow public void broadcastChanges() {}
@Shadow private int quickcraftStatus;
@Shadow protected abstract void resetQuickCraft();
@Shadow private int quickcraftType;
@Shadow @Final private Set<Slot> quickcraftSlots;
@Shadow public abstract boolean canDragTo(Slot slotIn);
@Shadow public abstract ItemStack quickMoveStack(Player playerIn, int index);
@Shadow public abstract boolean canTakeItemForPickAll(ItemStack stack, Slot slotIn);
@Shadow @Final public int containerId;
@Shadow public abstract Slot getSlot(int slotId);
@Shadow public static int getQuickcraftHeader(int clickedButton) { return 0; }
@Shadow public static int getQuickcraftType(int eventButton) { return 0; }
@Shadow public static boolean isValidQuickcraftType(int dragModeIn, Player player) { return false; }
@Shadow public static boolean canItemQuickReplace(@Nullable Slot slotIn, ItemStack stack, boolean stackSizeMatters) { return false; }
@Shadow public static void getQuickCraftSlotCount(Set<Slot> dragSlotsIn, int dragModeIn, ItemStack stack, int slotStackSize) { }
@Shadow protected abstract boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection);
@Shadow @Final @javax.annotation.Nullable private MenuType<?> menuType;
@Shadow private ItemStack remoteCarried;
@Shadow public abstract ItemStack getCarried();
@Shadow @javax.annotation.Nullable private ContainerSynchronizer synchronizer;
@Shadow public abstract void setCarried(ItemStack p_150439_);
@Shadow public NonNullList<Slot> slots;
@Shadow protected abstract SlotAccess createCarriedSlotAccess();
@Shadow public abstract void sendAllDataToRemote();
@Shadow public abstract int incrementStateId();
// @formatter:on
public boolean checkReachable = true;
private InventoryView bukkitView;
private long bukkitViewHash = 0;
public InventoryView getBukkitView() {
if (bukkitView != null && bukkitViewHash != bukkitViewHash()) {
ArclightContainer.updateView((AbstractContainerMenu) (Object) this, bukkitView);
bukkitViewHash = bukkitViewHash();
}
if (bukkitView == null) {
bukkitView = ArclightContainer.createInvView((AbstractContainerMenu) (Object) this);
bukkitViewHash = bukkitViewHash();
}
return bukkitView;
}
private long bukkitViewHash() {
return (((long) this.slots.size()) << 32) | System.identityHashCode(this.slots);
}
public void transferTo(AbstractContainerMenu other, CraftHumanEntity player) {
InventoryView source = this.getBukkitView();
InventoryView destination = ((ContainerBridge) other).bridge$getBukkitView();
((IInventoryBridge) ((CraftInventory) source.getTopInventory()).getInventory()).onClose(player);
((IInventoryBridge) ((CraftInventory) source.getBottomInventory()).getInventory()).onClose(player);
((IInventoryBridge) ((CraftInventory) destination.getTopInventory()).getInventory()).onOpen(player);
((IInventoryBridge) ((CraftInventory) destination.getBottomInventory()).getInventory()).onOpen(player);
}
private Component title;
public final Component getTitle() {
if (this.title == null) {
if (this.menuType != null && this.menuType.getRegistryName() != null) {
return new TextComponent(this.menuType.getRegistryName().toString());
} else {
return new TextComponent(this.toString());
}
}
return this.title;
}
public final void setTitle(Component title) {
if (this.title == null) {
if (title == null) {
this.title = getTitle();
} else {
this.title = title;
}
}
}
public void broadcastCarriedItem() {
this.remoteCarried = this.getCarried().copy();
if (this.synchronizer != null) {
this.synchronizer.sendCarriedChange((AbstractContainerMenu) (Object) this, this.remoteCarried);
}
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private void doClick(int slotId, int dragType, ClickType clickType, Player player) {
Inventory inventory = player.getInventory();
if (clickType == ClickType.QUICK_CRAFT) {
int j1 = this.quickcraftStatus;
this.quickcraftStatus = getQuickcraftHeader(dragType);
if ((j1 != 1 || this.quickcraftStatus != 2) && j1 != this.quickcraftStatus) {
this.resetQuickCraft();
} else if (this.getCarried().isEmpty()) {
this.resetQuickCraft();
} else if (this.quickcraftStatus == 0) {
this.quickcraftType = getQuickcraftType(dragType);
if (isValidQuickcraftType(this.quickcraftType, player)) {
this.quickcraftStatus = 1;
this.quickcraftSlots.clear();
} else {
this.resetQuickCraft();
}
} else if (this.quickcraftStatus == 1) {
Slot slot7 = this.slots.get(slotId);
ItemStack itemstack12 = this.getCarried();
if (canItemQuickReplace(slot7, itemstack12, true) && slot7.mayPlace(itemstack12) && (this.quickcraftType == 2 || itemstack12.getCount() > this.quickcraftSlots.size()) && this.canDragTo(slot7)) {
this.quickcraftSlots.add(slot7);
}
} else if (this.quickcraftStatus == 2) {
if (!this.quickcraftSlots.isEmpty()) {
if (false && this.quickcraftSlots.size() == 1) {
int l = (this.quickcraftSlots.iterator().next()).index;
this.resetQuickCraft();
this.doClick(l, this.quickcraftType, ClickType.PICKUP, player);
return;
}
ItemStack itemstack9 = this.getCarried().copy();
int k1 = this.getCarried().getCount();
Map<Integer, ItemStack> draggedSlots = new HashMap<>();
for (Slot slot8 : this.quickcraftSlots) {
ItemStack itemstack13 = this.getCarried();
if (slot8 != null && canItemQuickReplace(slot8, itemstack13, true) && slot8.mayPlace(itemstack13) && (this.quickcraftType == 2 || itemstack13.getCount() >= this.quickcraftSlots.size()) && this.canDragTo(slot8)) {
ItemStack itemstack14 = itemstack9.copy();
int j3 = slot8.hasItem() ? slot8.getItem().getCount() : 0;
getQuickCraftSlotCount(this.quickcraftSlots, this.quickcraftType, itemstack14, j3);
int k3 = Math.min(itemstack14.getMaxStackSize(), slot8.getMaxStackSize(itemstack14));
if (itemstack14.getCount() > k3) {
itemstack14.setCount(k3);
}
k1 -= itemstack14.getCount() - j3;
// slot8.set(itemstack14);
draggedSlots.put(slot8.index, itemstack14);
}
}
InventoryView view = this.getBukkitView();
org.bukkit.inventory.ItemStack newcursor = CraftItemStack.asCraftMirror(itemstack9);
newcursor.setAmount(k1);
Map<Integer, org.bukkit.inventory.ItemStack> eventmap = new HashMap<>();
for (Map.Entry<Integer, ItemStack> ditem : draggedSlots.entrySet()) {
eventmap.put(ditem.getKey(), CraftItemStack.asBukkitCopy(ditem.getValue()));
}
ItemStack oldCursor = this.getCarried();
this.setCarried(CraftItemStack.asNMSCopy(newcursor));
InventoryDragEvent event = new InventoryDragEvent(view, (newcursor.getType() != org.bukkit.Material.AIR ? newcursor : null), CraftItemStack.asBukkitCopy(oldCursor), this.quickcraftType == 1, eventmap);
Bukkit.getPluginManager().callEvent(event);
boolean needsUpdate = event.getResult() != Event.Result.DEFAULT;
if (event.getResult() != Event.Result.DENY) {
for (Map.Entry<Integer, ItemStack> dslot : draggedSlots.entrySet()) {
view.setItem(dslot.getKey(), CraftItemStack.asBukkitCopy(dslot.getValue()));
}
if (this.getCarried() != null) {
this.setCarried(CraftItemStack.asNMSCopy(event.getCursor()));
needsUpdate = true;
}
} else {
this.setCarried(oldCursor);
}
if (needsUpdate && player instanceof ServerPlayer) {
this.sendAllDataToRemote();
}
}
this.resetQuickCraft();
} else {
this.resetQuickCraft();
}
} else if (this.quickcraftStatus != 0) {
this.resetQuickCraft();
} else if ((clickType == ClickType.PICKUP || clickType == ClickType.QUICK_MOVE) && (dragType == 0 || dragType == 1)) {
ClickAction clickaction = dragType == 0 ? ClickAction.PRIMARY : ClickAction.SECONDARY;
if (slotId == -999) {
if (!this.getCarried().isEmpty()) {
if (clickaction == ClickAction.PRIMARY) {
ItemStack carried = this.getCarried();
this.setCarried(ItemStack.EMPTY);
player.drop(carried, true);
} else {
player.drop(this.getCarried().split(1), true);
}
}
} else if (clickType == ClickType.QUICK_MOVE) {
if (slotId < 0) {
return;
}
Slot slot6 = this.slots.get(slotId);
if (!slot6.mayPickup(player)) {
return;
}
for (ItemStack itemstack9 = this.quickMoveStack(player, slotId); !itemstack9.isEmpty() && ItemStack.isSame(slot6.getItem(), itemstack9); itemstack9 = this.quickMoveStack(player, slotId)) {
}
} else {
if (slotId < 0) {
return;
}
Slot slot7 = this.slots.get(slotId);
ItemStack itemstack10 = slot7.getItem();
ItemStack itemstack11 = this.getCarried();
player.updateTutorialInventoryAction(itemstack11, slot7.getItem(), clickaction);
if (!itemstack11.overrideStackedOnOther(slot7, clickaction, player) && !itemstack10.overrideOtherStackedOnMe(itemstack11, slot7, clickaction, player, this.createCarriedSlotAccess())) {
if (itemstack10.isEmpty()) {
if (!itemstack11.isEmpty()) {
int l2 = clickaction == ClickAction.PRIMARY ? itemstack11.getCount() : 1;
this.setCarried(slot7.safeInsert(itemstack11, l2));
}
} else if (slot7.mayPickup(player)) {
if (itemstack11.isEmpty()) {
int i3 = clickaction == ClickAction.PRIMARY ? itemstack10.getCount() : (itemstack10.getCount() + 1) / 2;
Optional<ItemStack> optional1 = slot7.tryRemove(i3, Integer.MAX_VALUE, player);
optional1.ifPresent((p_150421_) -> {
this.setCarried(p_150421_);
slot7.onTake(player, p_150421_);
});
} else if (slot7.mayPlace(itemstack11)) {
if (ItemStack.isSameItemSameTags(itemstack10, itemstack11)) {
int j3 = clickaction == ClickAction.PRIMARY ? itemstack11.getCount() : 1;
this.setCarried(slot7.safeInsert(itemstack11, j3));
} else if (itemstack11.getCount() <= slot7.getMaxStackSize(itemstack11)) {
slot7.set(itemstack11);
this.setCarried(itemstack10);
}
} else if (ItemStack.isSameItemSameTags(itemstack10, itemstack11)) {
Optional<ItemStack> optional = slot7.tryRemove(itemstack10.getCount(), itemstack11.getMaxStackSize() - itemstack11.getCount(), player);
optional.ifPresent((p_150428_) -> {
itemstack11.grow(p_150428_.getCount());
slot7.onTake(player, p_150428_);
});
}
}
}
slot7.setChanged();
if (player instanceof ServerPlayer && slot7.getMaxStackSize() != 64) {
((ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, this.incrementStateId(), slot7.index, slot7.getItem()));
// Updating a crafting inventory makes the client reset the result slot, have to send it again
if (this.getBukkitView().getType() == InventoryType.WORKBENCH || this.getBukkitView().getType() == InventoryType.CRAFTING) {
((ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, this.incrementStateId(), 0, this.getSlot(0).getItem()));
}
}
}
} else if (clickType == ClickType.SWAP) {
Slot slot2 = this.slots.get(slotId);
ItemStack itemstack4 = inventory.getItem(dragType);
ItemStack itemstack7 = slot2.getItem();
if (!itemstack4.isEmpty() || !itemstack7.isEmpty()) {
if (itemstack4.isEmpty()) {
if (slot2.mayPickup(player)) {
inventory.setItem(dragType, itemstack7);
((SlotBridge) slot2).bridge$onSwapCraft(itemstack7.getCount());
slot2.set(ItemStack.EMPTY);
slot2.onTake(player, itemstack7);
}
} else if (itemstack7.isEmpty()) {
if (slot2.mayPlace(itemstack4)) {
int l1 = slot2.getMaxStackSize(itemstack4);
if (itemstack4.getCount() > l1) {
slot2.set(itemstack4.split(l1));
} else {
slot2.set(itemstack4);
inventory.setItem(dragType, ItemStack.EMPTY);
}
}
} else if (slot2.mayPickup(player) && slot2.mayPlace(itemstack4)) {
int i2 = slot2.getMaxStackSize(itemstack4);
if (itemstack4.getCount() > i2) {
slot2.set(itemstack4.split(i2));
slot2.onTake(player, itemstack7);
if (!inventory.add(itemstack7)) {
player.drop(itemstack7, true);
}
} else {
slot2.set(itemstack4);
inventory.setItem(dragType, itemstack7);
slot2.onTake(player, itemstack7);
}
}
}
} else if (clickType == ClickType.CLONE && player.getAbilities().instabuild && this.getCarried().isEmpty() && slotId >= 0) {
Slot slot5 = this.slots.get(slotId);
if (slot5.hasItem()) {
ItemStack itemstack6 = slot5.getItem().copy();
itemstack6.setCount(itemstack6.getMaxStackSize());
this.setCarried(itemstack6);
}
} else if (clickType == ClickType.THROW && this.getCarried().isEmpty() && slotId >= 0) {
Slot slot4 = this.slots.get(slotId);
int i1 = dragType == 0 ? 1 : slot4.getItem().getCount();
ItemStack itemstack8 = slot4.safeTake(i1, Integer.MAX_VALUE, player);
player.drop(itemstack8, true);
} else if (clickType == ClickType.PICKUP_ALL && slotId >= 0) {
Slot slot3 = this.slots.get(slotId);
ItemStack itemstack5 = this.getCarried();
if (!itemstack5.isEmpty() && (!slot3.hasItem() || !slot3.mayPickup(player))) {
int k1 = dragType == 0 ? 0 : this.slots.size() - 1;
int j2 = dragType == 0 ? 1 : -1;
for (int k2 = 0; k2 < 2; ++k2) {
for (int k3 = k1; k3 >= 0 && k3 < this.slots.size() && itemstack5.getCount() < itemstack5.getMaxStackSize(); k3 += j2) {
Slot slot8 = this.slots.get(k3);
if (slot8.hasItem() && canItemQuickReplace(slot8, itemstack5, true) && slot8.mayPickup(player) && this.canTakeItemForPickAll(itemstack5, slot8)) {
ItemStack itemstack12 = slot8.getItem();
if (k2 != 0 || itemstack12.getCount() != itemstack12.getMaxStackSize()) {
ItemStack itemstack13 = slot8.safeTake(itemstack12.getCount(), itemstack5.getMaxStackSize() - itemstack5.getCount(), player);
itemstack5.grow(itemstack13.getCount());
}
}
}
}
}
}
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void removed(Player player) {
if (player instanceof ServerPlayer) {
ItemStack itemstack = this.getCarried();
if (!itemstack.isEmpty()) {
this.setCarried(ItemStack.EMPTY); // CraftBukkit - SPIGOT-4556 - from below
if (player.isAlive() && !((ServerPlayer) player).hasDisconnected()) {
player.getInventory().placeItemBackInInventory(itemstack);
} else {
player.drop(itemstack, false);
}
// this.setCarried(ItemStack.EMPTY); // CraftBukkit - moved up
}
}
}
@Override
public boolean bridge$isCheckReachable() {
return checkReachable;
}
@Override
public InventoryView bridge$getBukkitView() {
return getBukkitView();
}
@Override
public void bridge$transferTo(AbstractContainerMenu other, CraftHumanEntity player) {
transferTo(other, player);
}
@Override
public Component bridge$getTitle() {
return getTitle();
}
@Override
public void bridge$setTitle(Component title) {
setTitle(title);
}
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import net.minecraft.world.Container;
@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(AbstractFurnaceMenu.class)
public abstract class AbstractFurnaceContainerMixin extends ContainerMixin {
public abstract class AbstractFurnaceContainerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final private Container container;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import net.minecraft.world.Container;
@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(BeaconMenu.class)
public abstract class BeaconContainerMixin extends ContainerMixin {
public abstract class BeaconContainerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final private Container beacon;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import net.minecraft.world.Container;
@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(BrewingStandMenu.class)
public abstract class BrewingStandContainerMixin extends ContainerMixin {
public abstract class BrewingStandContainerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final private Container brewingStand;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(targets = "net/minecraft/world/inventory/CartographyTableMenu$1")
public abstract class CartographyContainer1Mixin implements IInventoryBridge {
@Shadow(aliases = {"this$0", "field_213911_a"}, remap = false) private CartographyTableMenu outerThis;
@Shadow(aliases = {"this$0", "f_39177_"}, remap = false) private CartographyTableMenu outerThis;
@Override
public Location getLocation() {

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(targets = "net/minecraft/world/inventory/CartographyTableMenu$2")
public abstract class CartographyContainer2Mixin implements IInventoryBridge {
@Shadow(aliases = {"this$0", "field_213924_a"}, remap = false) private CartographyTableMenu outerThis;
@Shadow(aliases = {"this$0", "f_39182_"}, remap = false) private CartographyTableMenu outerThis;
@Override
public Location getLocation() {

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(CartographyTableMenu.class)
public abstract class CartographyContainerMixin extends ContainerMixin implements PosContainerBridge {
public abstract class CartographyContainerMixin extends AbstractContainerMenuMixin implements PosContainerBridge {
// @formatter:off
@Shadow @Final private ContainerLevelAccess access;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import net.minecraft.world.CompoundContainer;
@ -21,7 +21,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ChestMenu.class)
public abstract class ChestContainerMixin extends ContainerMixin {
public abstract class ChestContainerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final private Container container;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.container.LecternContainerBridge;
import net.minecraft.core.Registry;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import org.bukkit.Location;

View File

@ -1,9 +1,16 @@
package io.izzel.arclight.common.mixin.core.inventory;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.inventory.CraftingInventoryBridge;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
import net.minecraft.core.NonNullList;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.entity.HumanEntity;
@ -15,13 +22,6 @@ import org.spongepowered.asm.mixin.Shadow;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.core.NonNullList;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
@Mixin(CraftingContainer.class)
public abstract class CraftingInventoryMixin implements CraftingInventoryBridge, Container {

View File

@ -1,27 +1,10 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.inventory.CraftingInventoryBridge;
import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryCrafting;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Optional;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
@ -31,13 +14,27 @@ import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.CraftingMenu;
import net.minecraft.world.inventory.ResultContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.RepairItemRecipe;
import net.minecraft.world.level.Level;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryCrafting;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Optional;
// todo 实现
@Mixin(CraftingMenu.class)
public abstract class WorkbenchContainerMixin extends ContainerMixin implements PosContainerBridge {
public abstract class CraftingMenuMixin extends AbstractContainerMenuMixin implements PosContainerBridge {
// @formatter:off
@Mutable @Shadow @Final private CraftingContainer craftSlots;
@ -53,39 +50,22 @@ public abstract class WorkbenchContainerMixin extends ContainerMixin implements
if (!bridge$isCheckReachable()) cir.setReturnValue(true);
}
private static void a(int id, Level world, Player player, CraftingContainer inventory, ResultContainer inventoryResult, AbstractContainerMenu container) {
ArclightCaptures.captureWorkbenchContainer(container);
slotChangedCraftingGrid(id, world, player, inventory, inventoryResult);
}
@Inject(method = "slotsChanged", at = @At("HEAD"))
public void arclight$capture(Container inventoryIn, CallbackInfo ci) {
ArclightCaptures.captureWorkbenchContainer((CraftingMenu) (Object) this);
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static void slotChangedCraftingGrid(int i, Level world, Player playerEntity, CraftingContainer inventory, ResultContainer resultInventory) {
AbstractContainerMenu container = ArclightCaptures.getWorkbenchContainer();
if (!world.isClientSide) {
ServerPlayer serverplayerentity = (ServerPlayer) playerEntity;
ItemStack itemstack = ItemStack.EMPTY;
Optional<CraftingRecipe> optional = world.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventory, world);
if (optional.isPresent()) {
CraftingRecipe icraftingrecipe = optional.get();
if (resultInventory.setRecipeUsed(world, serverplayerentity, icraftingrecipe)) {
itemstack = icraftingrecipe.assemble(inventory);
}
}
private static transient boolean arclight$isRepair;
itemstack = CraftEventFactory.callPreCraftEvent(inventory, resultInventory, itemstack, ((ContainerBridge) container).bridge$getBukkitView(), false);
@Redirect(method = "slotChangedCraftingGrid", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Optional;isPresent()Z"))
private static boolean arclight$testRepair(Optional<?> optional) {
arclight$isRepair = optional.orElse(null) instanceof RepairItemRecipe;
return optional.isPresent();
}
resultInventory.setItem(0, itemstack);
serverplayerentity.connection.send(new ClientboundContainerSetSlotPacket(i, 0, itemstack));
}
@ModifyVariable(method = "slotChangedCraftingGrid", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/ResultContainer;setItem(ILnet/minecraft/world/item/ItemStack;)V"))
private static ItemStack arclight$preCraft(ItemStack stack, AbstractContainerMenu container, Level level, Player player, CraftingContainer craftingContainer, ResultContainer resultContainer) {
return CraftEventFactory.callPreCraftEvent(craftingContainer, resultContainer, stack, ((ContainerBridge) container).bridge$getBukkitView(), arclight$isRepair);
}
@Inject(method = "<init>(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN"))

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import net.minecraft.world.Container;
@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(DispenserMenu.class)
public abstract class DispenserContainerMixin extends ContainerMixin {
public abstract class DispenserContainerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final public Container dispenser;

View File

@ -1,16 +1,16 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin;
import io.izzel.arclight.common.mixin.core.world.SimpleContainerMixin;
import net.minecraft.world.inventory.EnchantmentMenu;
import org.bukkit.Location;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(targets = "net/minecraft/world/inventory/EnchantmentMenu$1")
public abstract class EnchantmentContainer1Mixin extends InventoryMixin {
public abstract class EnchantmentContainer1Mixin extends SimpleContainerMixin {
@Shadow(aliases = {"this$0", "field_70484_a"}, remap = false) private EnchantmentMenu outerThis;
@Shadow(aliases = {"this$0", "f_39494_"}, remap = false) private EnchantmentMenu outerThis;
@Override
public Location getLocation() {

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
@ -51,7 +51,7 @@ import java.util.Map;
import java.util.Random;
@Mixin(EnchantmentMenu.class)
public abstract class EnchantmentContainerMixin extends ContainerMixin implements PosContainerBridge {
public abstract class EnchantmentContainerMixin extends AbstractContainerMenuMixin implements PosContainerBridge {
// @formatter:off
@Shadow @Final private Container enchantSlots;
@ -185,9 +185,9 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement
ItemStack itemstack = this.enchantSlots.getItem(0);
ItemStack itemstack1 = this.enchantSlots.getItem(1);
int i = id + 1;
if ((itemstack1.isEmpty() || itemstack1.getCount() < i) && !playerIn.abilities.instabuild) {
if ((itemstack1.isEmpty() || itemstack1.getCount() < i) && !playerIn.getAbilities().instabuild) {
return false;
} else if (this.costs[id] <= 0 || itemstack.isEmpty() || (playerIn.experienceLevel < i || playerIn.experienceLevel < this.costs[id]) && !playerIn.abilities.instabuild) {
} else if (this.costs[id] <= 0 || itemstack.isEmpty() || (playerIn.experienceLevel < i || playerIn.experienceLevel < this.costs[id]) && !playerIn.getAbilities().instabuild) {
return false;
} else {
this.access.execute((p_217003_6_, p_217003_7_) -> {
@ -207,7 +207,7 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement
Bukkit.getPluginManager().callEvent(event);
int level = event.getExpLevelCost();
if (event.isCancelled() || (level > playerIn.experienceLevel && !playerIn.abilities.instabuild) || event.getEnchantsToAdd().isEmpty()) {
if (event.isCancelled() || (level > playerIn.experienceLevel && !playerIn.getAbilities().instabuild) || event.getEnchantsToAdd().isEmpty()) {
return;
}
@ -242,7 +242,7 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement
}
playerIn.onEnchantmentPerformed(itemstack, i);
if (!playerIn.abilities.instabuild) {
if (!playerIn.getAbilities().instabuild) {
itemstack1.shrink(i);
if (itemstack1.isEmpty()) {
this.enchantSlots.setItem(1, ItemStack.EMPTY);

View File

@ -1,7 +1,8 @@
package io.izzel.arclight.common.mixin.core.inventory;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import io.izzel.arclight.common.mixin.core.world.SimpleContainerMixin;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.PlayerEnderChestContainer;
@ -15,7 +16,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(PlayerEnderChestContainer.class)
public abstract class EnderChestInventoryMixin extends InventoryMixin implements IInventoryBridge, Container {
public abstract class EnderChestInventoryMixin extends SimpleContainerMixin implements IInventoryBridge, Container {
// @formatter:off
@Shadow private EnderChestBlockEntity activeChest;

View File

@ -1,14 +1,14 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.tileentity.AbstractFurnaceTileEntityBridge;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.inventory.FurnaceResultSlot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import io.izzel.arclight.common.bridge.tileentity.AbstractFurnaceTileEntityBridge;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.FurnaceResultSlot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
@Mixin(FurnaceResultSlot.class)
public class FurnaceResultSlotMixin {
@ -17,8 +17,8 @@ public class FurnaceResultSlotMixin {
@Shadow private int removeCount;
// @formatter:on
@Redirect(method = "checkTakeAchievements(Lnet/minecraft/world/item/ItemStack;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity;awardUsedRecipesAndPopExperience(Lnet/minecraft/world/entity/player/Player;)V"))
public void arclight$furnaceDropExp(AbstractFurnaceBlockEntity furnace, Player playerEntity, ItemStack stack) {
((AbstractFurnaceTileEntityBridge) furnace).bridge$dropExp(playerEntity.level, playerEntity.position(), playerEntity, stack, this.removeCount);
@Redirect(method = "checkTakeAchievements(Lnet/minecraft/world/item/ItemStack;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity;awardUsedRecipesAndPopExperience(Lnet/minecraft/server/level/ServerPlayer;)V"))
public void arclight$furnaceDropExp(AbstractFurnaceBlockEntity furnace, ServerPlayer player, ItemStack stack) {
((AbstractFurnaceTileEntityBridge) furnace).bridge$dropExp(player.level, player.position(), player, stack, this.removeCount);
}
}

View File

@ -1,16 +1,16 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin;
import io.izzel.arclight.common.mixin.core.world.SimpleContainerMixin;
import net.minecraft.world.inventory.GrindstoneMenu;
import org.bukkit.Location;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(targets = "net/minecraft/world/inventory/GrindstoneMenu$1")
public abstract class GrindstoneContainer1Mixin extends InventoryMixin {
public abstract class GrindstoneContainer1Mixin extends SimpleContainerMixin {
@Shadow(aliases = {"this$0", "field_213912_a"}, remap = false) private GrindstoneMenu outerThis;
@Shadow(aliases = {"this$0", "f_39594_"}, remap = false) private GrindstoneMenu outerThis;
@Override
public Location getLocation() {

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
@ -17,9 +17,9 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GrindstoneMenu.class)
public abstract class GrindstoneContainerMixin extends ContainerMixin implements PosContainerBridge {
public abstract class GrindstoneContainerMixin extends AbstractContainerMenuMixin implements PosContainerBridge {
@Shadow @Final private Container repairSlots;
@Shadow @Final Container repairSlots;
@Shadow @Final private Container resultSlots;
@Shadow @Final private ContainerLevelAccess access;
private CraftInventoryView bukkitEntity = null;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import net.minecraft.world.Container;
@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(HopperMenu.class)
public abstract class HopperContainerMixin extends ContainerMixin {
public abstract class HopperContainerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final private Container hopper;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(HorseInventoryMenu.class)
public abstract class HorseInventoryContainerMixin extends ContainerMixin {
public abstract class HorseInventoryContainerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final private Container horseContainer;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ItemCombinerMenu.class)
public abstract class AbstractRepairContainerMixin extends ContainerMixin {
public abstract class ItemCombinerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final protected ContainerLevelAccess access;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.inventory.container.LecternContainerBridge;
@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LecternMenu.class)
public abstract class LecternContainerMixin extends ContainerMixin implements LecternContainerBridge {
public abstract class LecternContainerMixin extends AbstractContainerMenuMixin implements LecternContainerBridge {
// @formatter:off
@Shadow @Final private Container lectern;

View File

@ -1,16 +1,16 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin;
import io.izzel.arclight.common.mixin.core.world.SimpleContainerMixin;
import net.minecraft.world.inventory.LoomMenu;
import org.bukkit.Location;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(targets = "net/minecraft/world/inventory/LoomMenu$1")
public abstract class LoomContainer1Mixin extends InventoryMixin {
public abstract class LoomContainer1Mixin extends SimpleContainerMixin {
@Shadow(aliases = {"this$0", "field_213913_a"}, remap = false) private LoomMenu outerThis;
@Shadow(aliases = {"this$0", "f_39900_"}, remap = false) private LoomMenu outerThis;
@Override
public Location getLocation() {

View File

@ -1,16 +1,16 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin;
import io.izzel.arclight.common.mixin.core.world.SimpleContainerMixin;
import net.minecraft.world.inventory.LoomMenu;
import org.bukkit.Location;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(targets = "net/minecraft/world/inventory/LoomMenu$2")
public abstract class LoomContainer2Mixin extends InventoryMixin {
public abstract class LoomContainer2Mixin extends SimpleContainerMixin {
@Shadow(aliases = {"this$0", "field_213914_a"}, remap = false) private LoomMenu outerThis;
@Shadow(aliases = {"this$0", "f_39905_"}, remap = false) private LoomMenu outerThis;
@Override
public Location getLocation() {

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LoomMenu.class)
public abstract class LoomContainerMixin extends ContainerMixin implements PosContainerBridge {
public abstract class LoomContainerMixin extends AbstractContainerMenuMixin implements PosContainerBridge {
// @formatter:off
@Shadow @Final private Container inputContainer;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import net.minecraft.world.entity.Entity;
@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MerchantMenu.class)
public abstract class MerchantContainerMixin extends ContainerMixin {
public abstract class MerchantContainerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final private Merchant trader;

View File

@ -1,7 +1,14 @@
package io.izzel.arclight.common.mixin.core.inventory;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import net.minecraft.core.NonNullList;
import net.minecraft.world.Container;
import net.minecraft.world.entity.npc.AbstractVillager;
import net.minecraft.world.inventory.MerchantContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.trading.Merchant;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.entity.CraftAbstractVillager;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
@ -13,13 +20,6 @@ import org.spongepowered.asm.mixin.Shadow;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.core.NonNullList;
import net.minecraft.world.Container;
import net.minecraft.world.entity.npc.AbstractVillager;
import net.minecraft.world.inventory.MerchantContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.trading.Merchant;
@Mixin(MerchantContainer.class)
public abstract class MerchantInventoryMixin implements IInventoryBridge, Container {

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.inventory.CraftingInventoryBridge;
@ -21,7 +21,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(InventoryMenu.class)
public abstract class PlayerContainerMixin extends ContainerMixin {
public abstract class PlayerContainerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final private CraftingContainer craftSlots;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.util.IWorldPosCallableBridge;
@ -25,7 +25,7 @@ import org.spongepowered.asm.mixin.Shadow;
import java.util.Map;
@Mixin(AnvilMenu.class)
public abstract class RepairContainerMixin extends AbstractRepairContainerMixin {
public abstract class RepairContainerMixin extends ItemCombinerMixin {
// @formatter:off
@Shadow @Final public DataSlot cost;
@ -116,7 +116,7 @@ public abstract class RepairContainerMixin extends AbstractRepairContainerMixin
int j2 = map1.get(enchantment1);
j2 = i2 == j2 ? j2 + 1 : Math.max(j2, i2);
boolean flag1 = enchantment1.canEnchant(itemstack);
if (this.player.abilities.instabuild || itemstack.getItem() == Items.ENCHANTED_BOOK) {
if (this.player.getAbilities().instabuild || itemstack.getItem() == Items.ENCHANTED_BOOK) {
flag1 = true;
}
@ -194,7 +194,7 @@ public abstract class RepairContainerMixin extends AbstractRepairContainerMixin
this.cost.set(maximumRepairCost - 1);
}
if (this.cost.get() >= maximumRepairCost && !this.player.abilities.instabuild) {
if (this.cost.get() >= maximumRepairCost && !this.player.getAbilities().instabuild) {
itemstack1 = ItemStack.EMPTY;
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import net.minecraft.world.Container;
@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ShulkerBoxMenu.class)
public abstract class ShulkerBoxContainerMixin extends ContainerMixin {
public abstract class ShulkerBoxContainerMixin extends AbstractContainerMenuMixin {
// @formatter:off
@Shadow @Final private Container container;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.container.SlotBridge;
import net.minecraft.world.inventory.Slot;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.util.IWorldPosCallableBridge;
@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(SmithingMenu.class)
public abstract class SmithingTableContainerMixin extends AbstractRepairContainerMixin {
public abstract class SmithingTableContainerMixin extends ItemCombinerMixin {
private CraftInventoryView bukkitEntity;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(targets = "net/minecraft/world/inventory/StonecutterMenu$1")
public abstract class StonecutterContainer1Mixin implements IInventoryBridge {
@Shadow(aliases = {"this$0", "field_213915_a"}, remap = false) private StonecutterMenu outerThis;
@Shadow(aliases = {"this$0", "f_40344_"}, remap = false) private StonecutterMenu outerThis;
@Override
public Location getLocation() {

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
package io.izzel.arclight.common.mixin.core.world.inventory;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge;
@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(StonecutterMenu.class)
public abstract class StonecutterContainerMixin extends ContainerMixin implements PosContainerBridge {
public abstract class StonecutterContainerMixin extends AbstractContainerMenuMixin implements PosContainerBridge {
// @formatter:off
@Shadow @Final public Container container;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.decoration.ArmorStand;
@ -22,7 +22,7 @@ public class ArmorStandItemMixin {
arclight$entity = armorStandEntity;
}
@Inject(method = "useOn", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z"))
@Inject(method = "useOn", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V"))
public void arclight$entityPlace(UseOnContext context, CallbackInfoReturnable<InteractionResult> cir) {
if (CraftEventFactory.callEntityPlaceEvent(context, arclight$entity).isCancelled()) {
cir.setReturnValue(InteractionResult.FAIL);

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import net.minecraft.core.BlockPos;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
@ -74,7 +74,7 @@ public class BoatItemMixin extends Item {
Boat boatentity = new Boat(worldIn, result.getLocation().x, result.getLocation().y, result.getLocation().z);
boatentity.setType(this.type);
boatentity.yRot = playerIn.yRot;
boatentity.setYRot(playerIn.getYRot());
if (!worldIn.noCollision(boatentity, boatentity.getBoundingBox().inflate(-0.1D))) {
return new InteractionResultHolder<>(InteractionResult.FAIL, itemstack);
} else {
@ -86,7 +86,7 @@ public class BoatItemMixin extends Item {
return new InteractionResultHolder<>(InteractionResult.PASS, itemstack);
}
if (!playerIn.abilities.instabuild) {
if (!playerIn.getAbilities().instabuild) {
itemstack.shrink(1);
}
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
@ -44,7 +44,7 @@ public abstract class BowItemMixin extends ProjectileWeaponItem {
public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) {
if (entityLiving instanceof Player) {
Player playerentity = (Player) entityLiving;
boolean flag = playerentity.abilities.instabuild || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, stack) > 0;
boolean flag = playerentity.getAbilities().instabuild || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, stack) > 0;
ItemStack itemstack = playerentity.getProjectile(stack);
int i = this.getUseDuration(stack) - timeLeft;
@ -58,12 +58,12 @@ public abstract class BowItemMixin extends ProjectileWeaponItem {
float f = getPowerForTime(i);
if (!((double) f < 0.1D)) {
boolean flag1 = playerentity.abilities.instabuild || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, stack, playerentity));
boolean flag1 = playerentity.getAbilities().instabuild || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, stack, playerentity));
if (!worldIn.isClientSide) {
ArrowItem arrowitem = (ArrowItem) (itemstack.getItem() instanceof ArrowItem ? itemstack.getItem() : Items.ARROW);
AbstractArrow abstractarrowentity = arrowitem.createArrow(worldIn, itemstack, playerentity);
abstractarrowentity = customArrow(abstractarrowentity);
abstractarrowentity.shootFromRotation(playerentity, playerentity.xRot, playerentity.yRot, 0.0F, f * 3.0F, 1.0F);
abstractarrowentity.shootFromRotation(playerentity, playerentity.getXRot(), playerentity.getYRot(), 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F) {
abstractarrowentity.setCritArrow(true);
}
@ -92,7 +92,7 @@ public abstract class BowItemMixin extends ProjectileWeaponItem {
stack.hurtAndBreak(1, playerentity, (player) -> {
player.broadcastBreakEvent(playerentity.getUsedItemHand());
});
if (flag1 || playerentity.abilities.instabuild && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW)) {
if (flag1 || playerentity.getAbilities().instabuild && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW)) {
abstractarrowentity.pickup = AbstractArrow.Pickup.CREATIVE_ONLY;
}
@ -106,11 +106,11 @@ public abstract class BowItemMixin extends ProjectileWeaponItem {
}
}
worldIn.playSound(null, playerentity.getX(), playerentity.getY(), playerentity.getZ(), SoundEvents.ARROW_SHOOT, SoundSource.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1 && !playerentity.abilities.instabuild) {
worldIn.playSound(null, playerentity.getX(), playerentity.getY(), playerentity.getZ(), SoundEvents.ARROW_SHOOT, SoundSource.PLAYERS, 1.0F, 1.0F / (worldIn.getRandom().nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1 && !playerentity.getAbilities().instabuild) {
itemstack.shrink(1);
if (itemstack.isEmpty()) {
playerentity.inventory.removeItem(itemstack);
playerentity.getInventory().removeItem(itemstack);
}
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import net.minecraft.core.BlockPos;
@ -15,7 +15,6 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BucketPickup;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
@ -36,15 +35,15 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
public abstract class BucketItemMixin {
// @formatter:off
@Shadow public abstract boolean emptyBucket(@javax.annotation.Nullable Player player, Level worldIn, BlockPos posIn, @javax.annotation.Nullable BlockHitResult rayTrace);
@Shadow public abstract boolean emptyContents(@javax.annotation.Nullable Player player, Level worldIn, BlockPos posIn, @javax.annotation.Nullable BlockHitResult rayTrace);
// @formatter:on
@Inject(method = "use", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/BucketPickup;takeLiquid(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/level/material/Fluid;"))
@Inject(method = "use", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/BucketPickup;pickupBlock(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/item/ItemStack;"))
private void arclight$bucketFill(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir, ItemStack stack, HitResult result) {
BlockPos pos = ((BlockHitResult) result).getBlockPos();
BlockState state = worldIn.getBlockState(pos);
Fluid dummyFluid = ((BucketPickup) state.getBlock()).takeLiquid(DummyGeneratorAccess.INSTANCE, pos, state);
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) worldIn, playerIn, pos, pos, ((BlockHitResult) result).getDirection(), stack, dummyFluid.getBucket());
ItemStack dummyFluid = ((BucketPickup) state.getBlock()).pickupBlock(DummyGeneratorAccess.INSTANCE, pos, state);
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) worldIn, playerIn, pos, pos, ((BlockHitResult) result).getDirection(), stack, dummyFluid.getItem());
if (event.isCancelled()) {
((ServerPlayer) playerIn).connection.send(new ClientboundBlockUpdatePacket(worldIn, pos));
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
@ -54,7 +53,7 @@ public abstract class BucketItemMixin {
}
}
@Inject(method = "use", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/BucketItem;emptyBucket(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/phys/BlockHitResult;)Z"))
@Inject(method = "use", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/BucketItem;emptyContents(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/phys/BlockHitResult;)Z"))
private void arclight$capture(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir, ItemStack stack, HitResult result) {
BlockHitResult blockRayTraceResult = (BlockHitResult) result;
arclight$direction = blockRayTraceResult.getDirection();
@ -72,7 +71,7 @@ public abstract class BucketItemMixin {
private transient org.bukkit.inventory.@Nullable ItemStack arclight$captureItem;
@ModifyArg(method = "onItemRightClick", index = 2, at = @At(value = "INVOKE", target = "Lnet/minecraft/util/DrinkHelper;fill(Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;"))
@ModifyArg(method = "use", index = 2, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemUtils;createFilledResult(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/ItemStack;"))
private ItemStack arclight$useEventItem(ItemStack itemStack) {
return arclight$captureItem == null ? itemStack : CraftItemStack.asNMSCopy(arclight$captureItem);
}
@ -82,7 +81,7 @@ public abstract class BucketItemMixin {
arclight$click = clicked;
arclight$stack = itemstack;
try {
return this.emptyBucket(entity, world, pos, result);
return this.emptyContents(entity, world, pos, result);
} finally {
arclight$direction = null;
arclight$click = null;
@ -94,7 +93,7 @@ public abstract class BucketItemMixin {
private transient BlockPos arclight$click;
private transient ItemStack arclight$stack;
@Inject(method = "emptyBucket", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/dimension/DimensionType;ultraWarm()Z"))
@Inject(method = "emptyContents", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/dimension/DimensionType;ultraWarm()Z"))
private void arclight$bucketEmpty(Player player, Level worldIn, BlockPos posIn, BlockHitResult rayTrace, CallbackInfoReturnable<Boolean> cir) {
if (player != null) {
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) worldIn, player, posIn, arclight$click, arclight$direction, arclight$stack);

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import net.minecraft.server.level.ServerPlayer;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.LivingEntityBridge;
import io.izzel.arclight.mixin.Eject;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.mixin.Eject;
@ -39,7 +39,7 @@ public abstract class EggItemMixin extends Item {
cir.setReturnValue(InteractionResultHolder.fail(playerIn.getItemInHand(handIn)));
return false;
} else {
worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.EGG_THROW, SoundSource.PLAYERS, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.EGG_THROW, SoundSource.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
return true;
}
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.mixin.Eject;
import net.minecraft.world.InteractionHand;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import net.minecraft.sounds.SoundEvents;
@ -34,7 +34,7 @@ public class EnderPearlItemMixin extends Item {
if (!worldIn.isClientSide) {
ThrownEnderpearl enderpearlentity = new ThrownEnderpearl(worldIn, playerIn);
enderpearlentity.setItem(itemstack);
enderpearlentity.shootFromRotation(playerIn, playerIn.xRot, playerIn.yRot, 0.0F, 1.5F, 1.0F);
enderpearlentity.shootFromRotation(playerIn, playerIn.getXRot(), playerIn.getYRot(), 0.0F, 1.5F, 1.0F);
if (!worldIn.addFreshEntity(enderpearlentity)) {
if (playerIn instanceof ServerPlayerEntityBridge) {
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
@ -43,11 +43,11 @@ public class EnderPearlItemMixin extends Item {
}
}
worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (worldIn.getRandom().nextFloat() * 0.4F + 0.8F));
playerIn.getCooldowns().addCooldown(this, 20);
playerIn.awardStat(Stats.ITEM_USED.get(this));
if (!playerIn.abilities.instabuild) {
if (!playerIn.getAbilities().instabuild) {
itemstack.shrink(1);
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionResult;
@ -20,7 +20,7 @@ public class FireChargeItemMixin {
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/FireChargeItem;playSound(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V"))
public void arclight$blockIgnite(UseOnContext context, CallbackInfoReturnable<InteractionResult> cir, Level world, BlockPos blockPos) {
if (CraftEventFactory.callBlockIgniteEvent(world, blockPos, BlockIgniteEvent.IgniteCause.FIREBALL, context.getPlayer()).isCancelled()) {
if (!context.getPlayer().abilities.instabuild) {
if (!context.getPlayer().getAbilities().instabuild) {
context.getItemInHand().shrink(1);
}
cir.setReturnValue(InteractionResult.PASS);

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
@ -44,7 +44,7 @@ public class FishingRodItemMixin extends Item {
}
playerIn.swing(handIn);
worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.FISHING_BOBBER_RETRIEVE, SoundSource.NEUTRAL, 1.0F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.FISHING_BOBBER_RETRIEVE, SoundSource.NEUTRAL, 1.0F, 0.4F / (worldIn.getRandom().nextFloat() * 0.4F + 0.8F));
} else {
if (!worldIn.isClientSide) {
int k = EnchantmentHelper.getFishingSpeedBonus(itemstack);
@ -58,7 +58,7 @@ public class FishingRodItemMixin extends Item {
playerIn.fishing = null;
return new InteractionResultHolder<>(InteractionResult.PASS, itemstack);
}
worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.FISHING_BOBBER_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.FISHING_BOBBER_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (worldIn.getRandom().nextFloat() * 0.4F + 0.8F));
worldIn.addFreshEntity(new FishingHook(playerIn, worldIn, j, k));
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionResult;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.item.ItemStackBridge;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
@ -43,7 +43,7 @@ public class LeadItemMixin {
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
leashknotentity.remove();
leashknotentity.discard();
return InteractionResult.PASS;
}
}

View File

@ -0,0 +1,40 @@
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.world.storage.MapDataBridge;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.MapItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import org.bukkit.Bukkit;
import org.bukkit.event.server.MapInitializeEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import javax.annotation.Nullable;
@Mixin(MapItem.class)
public abstract class MapItemMixin {
@Inject(method = "createNewSavedData", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN"))
private static void arclight$mapInit(Level p_151121_, int p_151122_, int p_151123_, int p_151124_, boolean p_151125_, boolean p_151126_, ResourceKey<Level> p_151127_, CallbackInfoReturnable<Integer> cir, MapItemSavedData mapData) {
MapInitializeEvent event = new MapInitializeEvent(((MapDataBridge) mapData).bridge$getMapView());
Bukkit.getPluginManager().callEvent(event);
}
/**
* @author IzzelAliz
* @reason
*/
@Nullable
@Overwrite
public static Integer getMapId(ItemStack stack) {
CompoundTag compoundnbt = stack.getTag();
return compoundnbt != null && compoundnbt.contains("map", 99) ? compoundnbt.getInt("map") : -1;
}
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.item.MerchantOfferBridge;
import net.minecraft.world.item.ItemStack;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.LivingEntityBridge;
import net.minecraft.world.entity.LivingEntity;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.mixin.Eject;
import net.minecraft.world.InteractionResult;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.LivingEntityBridge;
import net.minecraft.world.entity.LivingEntity;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import net.minecraft.server.level.ServerPlayer;
@ -36,11 +36,11 @@ public class SnowballItemMixin extends Item {
Snowball snowballentity = new Snowball(worldIn, playerIn);
snowballentity.setItem(itemstack);
if (worldIn.addFreshEntity(snowballentity)) {
if (!playerIn.abilities.instabuild) {
if (!playerIn.getAbilities().instabuild) {
itemstack.shrink(1);
}
worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
snowballentity.shootFromRotation(playerIn, playerIn.xRot, playerIn.yRot, 0.0F, 1.5F, 1.0F);
worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (worldIn.getRandom().nextFloat() * 0.4F + 0.8F));
snowballentity.shootFromRotation(playerIn, playerIn.getXRot(), playerIn.getYRot(), 0.0F, 1.5F, 1.0F);
} else if (playerIn instanceof ServerPlayer) {
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.world.WorldBridge;
import org.bukkit.event.entity.CreatureSpawnEvent;

View File

@ -1,8 +1,15 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.common.mixin.core.world.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.entity.projectile.TridentEntityBridge;
import io.izzel.arclight.mixin.Eject;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TridentItem;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.event.player.PlayerRiptideEvent;
@ -13,13 +20,6 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.function.Consumer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TridentItem;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
@Mixin(TridentItem.class)
public class TridentItemMixin {
@ -45,7 +45,7 @@ public class TridentItemMixin {
return true;
}
@Inject(method = "releaseUsing", at = @At(value = "FIELD", ordinal = 1, target = "Lnet/minecraft/world/entity/player/Player;yRot:F"))
@Inject(method = "releaseUsing", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/entity/player/Player;getYRot()F"))
public void arclight$riptide(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft, CallbackInfo ci) {
PlayerRiptideEvent event = new PlayerRiptideEvent(((ServerPlayerEntityBridge) entityLiving).bridge$getBukkitEntity(), CraftItemStack.asCraftMirror(stack));
Bukkit.getPluginManager().callEvent(event);

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item.crafting;
package io.izzel.arclight.common.mixin.core.world.item.crafting;
import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge;
import net.minecraft.resources.ResourceLocation;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item.crafting;
package io.izzel.arclight.common.mixin.core.world.item.crafting;
import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge;
import net.minecraft.resources.ResourceLocation;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item.crafting;
package io.izzel.arclight.common.mixin.core.world.item.crafting;
import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge;
import net.minecraft.world.item.crafting.CustomRecipe;
@ -6,7 +6,7 @@ import org.bukkit.inventory.Recipe;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(CustomRecipe.class)
public class SpecialRecipeMixin implements IRecipeBridge {
public class CustomRecipeMixin implements IRecipeBridge {
@Override
public Recipe bridge$toBukkitRecipe() {

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item.crafting;
package io.izzel.arclight.common.mixin.core.world.item.crafting;
import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge;
import net.minecraft.resources.ResourceLocation;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item.crafting;
package io.izzel.arclight.common.mixin.core.world.item.crafting;
import io.izzel.arclight.common.bridge.item.crafting.IngredientBridge;
import org.spongepowered.asm.mixin.Mixin;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item.crafting;
package io.izzel.arclight.common.mixin.core.world.item.crafting;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

Some files were not shown because too many files have changed in this diff Show More