Skip to content

Commit

Permalink
Rewrite net/minecraft/level/item
Browse files Browse the repository at this point in the history
  • Loading branch information
C0D3-M4513R committed Mar 19, 2024
1 parent 4b12476 commit f9496ce
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
--- a/net/minecraft/world/item/DebugStickItem.java
+++ b/net/minecraft/world/item/DebugStickItem.java
@@ -49,8 +_,8 @@
return InteractionResult.sidedSuccess(level.isClientSide);
@@ -50,7 +_,7 @@
}

- private boolean handleInteraction(Player p_150803_, BlockState p_150804_, LevelAccessor p_150805_, BlockPos p_150806_, boolean p_150807_, ItemStack p_150808_) {
public boolean handleInteraction(Player p_150803_, BlockState p_150804_, LevelAccessor p_150805_, BlockPos p_150806_, boolean p_150807_, ItemStack p_150808_) {
- if (!p_150803_.canUseGameMasterBlocks()) {
+ public boolean handleInteraction(Player p_150803_, BlockState p_150804_, LevelAccessor p_150805_, BlockPos p_150806_, boolean p_150807_, ItemStack p_150808_) {
+ if (!p_150803_.canUseGameMasterBlocks() && !(p_150803_.getAbilities().instabuild && p_150803_.getBukkitEntity().hasPermission("minecraft.debugstick")) && !p_150803_.getBukkitEntity().hasPermission("minecraft.debugstick.always")) { // Spigot
return false;
} else {
Expand Down
39 changes: 21 additions & 18 deletions patches/minecraft/net/minecraft/world/item/LeadItem.java.patch
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
--- a/net/minecraft/world/item/LeadItem.java
+++ b/net/minecraft/world/item/LeadItem.java
@@ -24,7 +_,7 @@
@@ -24,6 +_,7 @@
if (blockstate.is(BlockTags.FENCES)) {
Player player = p_42834_.getPlayer();
if (!level.isClientSide && player != null) {
- bindPlayerMobs(player, level, blockpos);
+ bindPlayerMobs(player, level, blockpos, p_42834_.getHand()); // CraftBukkit - Pass hand
+ ketting$bindPlayerMobs$interactionHand.set(p_42834_.getHand());// Ketting - CraftBukkit - Pass hand
bindPlayerMobs(player, level, blockpos);
}

return InteractionResult.sidedSuccess(level.isClientSide);
@@ -33,7 +_,7 @@
@@ -33,6 +_,14 @@
}
}

- public static InteractionResult bindPlayerMobs(Player p_42830_, Level p_42831_, BlockPos p_42832_) {
+ public static InteractionResult bindPlayerMobs(Player p_42830_, Level p_42831_, BlockPos p_42832_, net.minecraft.world.InteractionHand interactionHand) { // CraftBukkit - Add InteractionHand
+ //Ketting start
+ public static final java.util.concurrent.atomic.AtomicReference<net.minecraft.world.InteractionHand> ketting$bindPlayerMobs$interactionHand = new java.util.concurrent.atomic.AtomicReference<>(net.minecraft.world.InteractionHand.MAIN_HAND);
+ @SuppressWarnings("unused") //Ketting - CB compat
+ public static InteractionResult bindPlayerMobs(Player p_42830_, Level p_42831_, BlockPos p_42832_, net.minecraft.world.InteractionHand interactionHand) {
+ ketting$bindPlayerMobs$interactionHand.set(interactionHand);
+ return bindPlayerMobs(p_42830_, p_42831_, p_42832_);
+ }
+ //Ketting end
public static InteractionResult bindPlayerMobs(Player p_42830_, Level p_42831_, BlockPos p_42832_) {
LeashFenceKnotEntity leashfenceknotentity = null;
boolean flag = false;
double d0 = 7.0D;
@@ -45,9 +_,26 @@
@@ -45,9 +_,27 @@
if (mob.getLeashHolder() == p_42830_) {
if (leashfenceknotentity == null) {
leashfenceknotentity = LeashFenceKnotEntity.getOrCreateKnot(p_42831_, p_42832_);
+
+ // CraftBukkit start - fire HangingPlaceEvent
+ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.v1_20_R1.CraftEquipmentSlot.getHand(interactionHand);
+ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.v1_20_R1.CraftEquipmentSlot.getHand(ketting$bindPlayerMobs$interactionHand.get());//Ketting
+ org.bukkit.event.hanging.HangingPlaceEvent event = new org.bukkit.event.hanging.HangingPlaceEvent((org.bukkit.entity.Hanging) leashfenceknotentity.getBukkitEntity(), p_42830_ != null ? (org.bukkit.entity.Player) p_42830_.getBukkitEntity() : null, p_42831_.getWorld().getBlockAt(i, j, k), org.bukkit.block.BlockFace.SELF, hand);
+ p_42831_.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ leashfenceknotentity.discard();
+ ketting$bindPlayerMobs$interactionHand.set(null);
+ return InteractionResult.PASS;
+ }
+ // CraftBukkit end
leashfenceknotentity.playPlacementSound();
}

+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory.callPlayerLeashEntityEvent(mob, leashfenceknotentity, p_42830_, interactionHand).isCancelled()) {
+ if (org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory.callPlayerLeashEntityEvent(mob, leashfenceknotentity, p_42830_, ketting$bindPlayerMobs$interactionHand.get()).isCancelled()) {
+ continue;
+ }
+ // CraftBukkit end
+
mob.setLeashedTo(leashfenceknotentity, true);
flag = true;
}
@@ -59,4 +_,10 @@
@@ -57,6 +_,7 @@
p_42831_.gameEvent(GameEvent.BLOCK_ATTACH, p_42832_, GameEvent.Context.of(p_42830_));
}

+ ketting$bindPlayerMobs$interactionHand.set(net.minecraft.world.InteractionHand.MAIN_HAND); //Ketting
return flag ? InteractionResult.SUCCESS : InteractionResult.PASS;
}
+
+ // CraftBukkit start
+ public static InteractionResult bindPlayerMobs(Player p_42830_, Level p_42831_, BlockPos p_42832_) {
+ return bindPlayerMobs(p_42830_, p_42831_, p_42832_, net.minecraft.world.InteractionHand.MAIN_HAND);
+ }
+ // CraftBukkit end
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
--- a/net/minecraft/world/item/crafting/StonecutterRecipe.java
+++ b/net/minecraft/world/item/crafting/StonecutterRecipe.java
@@ -7,9 +_,11 @@
import net.minecraft.world.level.block.Blocks;

public class StonecutterRecipe extends SingleItemRecipe {
+ //Ketting start
public StonecutterRecipe(ResourceLocation p_44478_, String p_44479_, Ingredient p_44480_, ItemStack p_44481_) {
super(RecipeType.STONECUTTING, RecipeSerializer.STONECUTTER, p_44478_, p_44479_, p_44480_, p_44481_);
}
+ //Ketting end

public boolean matches(Container p_44483_, Level p_44484_) {
return this.ingredient.test(p_44483_.getItem(0));
@@ -18,4 +_,16 @@
public ItemStack getToastSymbol() {
return new ItemStack(Blocks.STONECUTTER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
--- a/net/minecraft/world/item/trading/MerchantOffer.java
+++ b/net/minecraft/world/item/trading/MerchantOffer.java
@@ -6,16 +_,32 @@
import net.minecraft.world.item.ItemStack;

public class MerchantOffer {
- private final ItemStack baseCostA;
- private final ItemStack costB;
- private final ItemStack result;
- private int uses;
- private final int maxUses;
- private boolean rewardExp = true;
- private int specialPriceDiff;
- private int demand;
- private float priceMultiplier;
- private int xp = 1;
+ public ItemStack baseCostA;
+ public ItemStack costB;
+ public final ItemStack result;
+ public int uses;
+ public int maxUses;
+ public boolean rewardExp = true;
+ public int specialPriceDiff;
+ public int demand;
+ public float priceMultiplier;
+ public int xp = 1;
@@ -16,6 +_,22 @@
public int demand;
public float priceMultiplier;
public int xp = 1;
+ // CraftBukkit start
+ private org.bukkit.craftbukkit.v1_20_R1.inventory.CraftMerchantRecipe bukkitHandle;
+
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/level/block/MultifaceSpreader.java
+++ b/net/minecraft/world/level/block/MultifaceSpreader.java
@@ -136,14 +_,16 @@
@@ -136,14 +_,19 @@
p_221702_.getChunk(p_221703_.pos()).markPosForPostprocessing(p_221703_.pos());
}

Expand All @@ -16,6 +16,9 @@
- public static record SpreadPos(BlockPos pos, Direction face) {
+ //Ketting - Todo: How do we fix this? Let's wait for an error to come around.
+ public static record SpreadPos(BlockPos pos, Direction face, BlockPos source) { // CraftBukkit
+ public SpreadPos(BlockPos pos, Direction face){
+ this(pos, face, null);
+ }
}

@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,7 @@ public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(Mob entity,

public static PlayerLeashEntityEvent callPlayerLeashEntityEvent(Mob entity, Entity leashHolder, net.minecraft.world.entity.player.Player player, InteractionHand enumhand) {
PlayerLeashEntityEvent event = new PlayerLeashEntityEvent(entity.getBukkitEntity(), leashHolder.getBukkitEntity(), (Player) player.getBukkitEntity(), CraftEquipmentSlot.getHand(enumhand));
if (enumhand != null) //Ketting
entity.level().getCraftServer().getPluginManager().callEvent(event);
return event;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1018,4 +1018,16 @@ public net.minecraft.world.level.block.entity.CampfireBlockEntity f_59044_ # coo

public net.minecraft.world.level.block.entity.BellBlockEntity f_58818_ # resonating
public net.minecraft.world.level.block.entity.BellBlockEntity f_58819_ # resonationTicks
public net.minecraft.world.item.DebugStickItem m_150802_(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;ZLnet/minecraft/world/item/ItemStack;)Z # handleInteraction

public-f net.minecraft.world.item.trading.MerchantOffer f_45310_ # baseCostA
public-f net.minecraft.world.item.trading.MerchantOffer f_45311_ # costB
public net.minecraft.world.item.trading.MerchantOffer f_45312_ # result
public net.minecraft.world.item.trading.MerchantOffer f_45313_ # uses
public-f net.minecraft.world.item.trading.MerchantOffer f_45314_ # maxUses
public net.minecraft.world.item.trading.MerchantOffer f_45315_ # rewardExp
public net.minecraft.world.item.trading.MerchantOffer f_45316_ # specialPriceDiff
public net.minecraft.world.item.trading.MerchantOffer f_45317_ # demand
public net.minecraft.world.item.trading.MerchantOffer f_45318_ # priceMultiplier
public net.minecraft.world.item.trading.MerchantOffer f_45319_ # xp
#endgroup KETTING

0 comments on commit f9496ce

Please sign in to comment.