Skip to content

Commit

Permalink
Merge pull request #15 from kettingpowered/1.20.x
Browse files Browse the repository at this point in the history
[skip ci] fix item entity patches
  • Loading branch information
C0D3-M4513R authored Nov 16, 2023
2 parents f4ade72 + c986ff4 commit 71c5578
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 77 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,8 @@ project(':forge') {
// Make sure we run bin compat checking during local testing.
if (!System.env.MAVEN_USER || !System.env.MAVEN_PASSWORD)
publish.dependsOn(':forge:checkJarCompatibility')

tasks.named('compileJava').get().mustRunAfter('extractMapped')
}

tasks.register('setup') {
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[discord-widget]: https://canary.discord.com/api/guilds/1172551819138965605/widget.png
[discord-invite]: https://discord.gg/jBHZDG9WS8
[discord-invite]: https://discord.kettingpowered.org/
[forge-version]: https://img.shields.io/badge/1.20.2--48.0.38-none?logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMjCGJ1kDAAACoElEQVQ4T22SeU8aURTF%2FULGtNRWWVQY9lXABWldIDPIMgVbNgEVtaa0damiqGBdipXaJcY2ofEf4ycbTt97pVAabzK5b27u%2BZ377kwXgK77QthRy7OfXbeJM%2BttqKSXN8sdwbT%2FA0L7elmsYqrPHZmROLPh5YkV4oEBwaKuHj%2ByyJptLDoAhbq3O1V1XCVObY3FL24mfn5oRPrcwSCRfQOyNWcjVjZdCbtcdwcgXrXUspdOKbDN%2FXE9tiBJMhXHT60gUIT2dMhcDLMc3NVKQklz0QIkf5qlyEcO6Qs7yPhMJB4amDMFimQSmqNlE8SKAZFzDfxHfVILIIZ10sJ3OwIbcqSuiOjchkzNCboHev9o2YhgiUP8mxnLN24I6%2F3ghYdtQG5iUMpFBuCP9iKwLsfiLyeCp2rMnZgwX3NArGoxW1Ridl%2BBzLEVKa8KSxOqNmDdz0kFnxaLHhWEgAyZigWhHXL%2BpEDy2ozsDxv8vAzTnh7w5kcghqCaFmCT10of4iPIT2mRdPUh4HoCcVwBH%2F8Ac2kzUkEV5r3EfVSOvbAJa5NDyI0r2oDtWb1EClh%2BOoC3Pg7v%2FBw7p939yI4rsRW2Y3lKh01eh7WpIRyKZqzyjjYgPdIvlaMWRqYuG7wWryYHsRM0sFolZiPvQ3jheIwSmSBPdkByG%2FB6Wi3RYiVmRX7GiAPiUCRisii8D%2BjZNKvPBrHCW1GY0bAz6WkDCtOaSyKQFsi4K5NqNiZtehN2Y5uAShETqolhBqJXpfdPuPsuWwAaRdHSkxdc11mPqkGnyY4pyKbpl1GyJ0Pel7yqBoFcF3zqno5f%2Bd8ohYy9Sx7lzQpxo1eirluCDgt%2B%2B00p6uxttrG4F%2FA39sJGZWZMfrcp6O6%2B5kaVzXJHAOj6DeSs8qw5o8oxAAAAAElFTkSuQmCC&labelColor=4e4e4e&color=2d2d2d
[forge-commit]: https://github.com/MinecraftForge/MinecraftForge/commit/83c651c
[build-status]: https://img.shields.io/github/actions/workflow/status/kettingpowered/Ketting-1-20-x/build_and_release.yml
Expand All @@ -21,7 +21,7 @@ that enables the use of Bukkit plugins on Forge servers.
Ketting is still in development and is not ready for production use.

### PATCHES DONE
Bukkit: 296 / 530
Bukkit: 303 / 530
<br>
CraftBukkit: 0 / 685

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,25 +212,30 @@
this.extinguishFire();
}

@@ -636,11 +_,17 @@
}

public void onEquipItem(EquipmentSlot p_238393_, ItemStack p_238394_, ItemStack p_238395_) {
+ // CraftBukkit start
+ onEquipItem(p_238393_, p_238394_, p_238395_, false);
+ }
+
+ public void onEquipItem(EquipmentSlot p_238393_, ItemStack p_238394_, ItemStack p_238395_, boolean silent) {
+ // CraftBukkit end
boolean flag = p_238395_.isEmpty() && p_238394_.isEmpty();
@@ -640,7 +_,7 @@
if (!flag && !ItemStack.isSameItemSameTags(p_238394_, p_238395_) && !this.firstTick) {
Equipable equipable = Equipable.get(p_238395_);
if (!this.level().isClientSide() && !this.isSpectator()) {
- if (!this.isSilent() && equipable != null && equipable.getEquipmentSlot() == p_238393_) {
+ if (!this.isSilent() && equipable != null && equipable.getEquipmentSlot() == p_238393_ && !silent) { // CraftBukkit
+ if (!this.isSilent() && equipable != null && equipable.getEquipmentSlot() == p_238393_ && !isSilentEquip()) { //Ketting
this.level().playSound((Player)null, this.getX(), this.getY(), this.getZ(), equipable.getEquipSound(), this.getSoundSource(), 1.0F, 1.0F);
}

@@ -652,6 +_,14 @@
}
}

+ //Ketting start - forge compat
+ public void onEquipItem(EquipmentSlot p_238393_, ItemStack p_238394_, ItemStack p_238395_, boolean silent) {
+ setSilentEquip(silent);
+ onEquipItem(p_238393_, p_238394_, p_238395_);
+ setSilentEquip(false);
+ }
+ //Ketting end
+
public void remove(Entity.RemovalReason p_276115_) {
super.remove(p_276115_);
this.brain.clearMemories();
@@ -704,6 +_,17 @@
}
}
Expand Down Expand Up @@ -1250,15 +1255,30 @@
}

protected void onBelowWorld() {
@@ -1895,6 +_,12 @@
@@ -1895,6 +_,27 @@

public abstract ItemStack getItemBySlot(EquipmentSlot p_21127_);

+ // CraftBukkit start
+ public void setItemSlot(EquipmentSlot slot, ItemStack itemstack, boolean silent) {
+ //Ketting start - no mixin injects pls
+ setSilentEquip(silent);
+ this.setItemSlot(slot, itemstack);
+ setSilentEquip(false);
+ //Ketting end
+ }
+ // CraftBukkit end
+
+ //Ketting start
+ private boolean setItemSlot$silent = false;
+ protected boolean isSilentEquip() {
+ return setItemSlot$silent;
+ }
+
+ protected void setSilentEquip(boolean silent) {
+ setItemSlot$silent = silent;
+ }
+ //Ketting end
+
public abstract void setItemSlot(EquipmentSlot p_21036_, ItemStack p_21037_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,15 @@
private boolean hasPhysics() {
return !this.isMarker() && !this.isNoGravity();
}
@@ -142,13 +_,18 @@
}

public void setItemSlot(EquipmentSlot p_31584_, ItemStack p_31585_) {
+ // CraftBukkit start
+ this.setItemSlot(p_31584_, p_31585_, false);
+ }
+
+ public void setItemSlot(EquipmentSlot p_31584_, ItemStack p_31585_, boolean silent) {
this.verifyEquippedItem(p_31585_);
switch (p_31584_.getType()) {
case HAND:
- this.onEquipItem(p_31584_, this.handItems.set(p_31584_.getIndex(), p_31585_), p_31585_);
+ this.onEquipItem(p_31584_, this.handItems.set(p_31584_.getIndex(), p_31585_), p_31585_, silent); // CraftBukkit
break;
@@ -150,7 +_,6 @@
case ARMOR:
- this.onEquipItem(p_31584_, this.armorItems.set(p_31584_.getIndex(), p_31585_), p_31585_);
+ this.onEquipItem(p_31584_, this.armorItems.set(p_31584_.getIndex(), p_31585_), p_31585_, silent); // CraftBukkit
this.onEquipItem(p_31584_, this.armorItems.set(p_31584_.getIndex(), p_31585_), p_31585_);
}
-
}
@@ -351,32 +_,61 @@

public boolean canTakeItem(ItemStack p_31638_) {
@@ -351,32 +_,60 @@
return false;
} else if (itemstack.isEmpty() && (this.disabledSlots & 1 << p_31590_.getFilterFlag() + 16) != 0) {
return false;
Expand All @@ -75,7 +62,7 @@
- return true;
- }
+ org.bukkit.inventory.ItemStack armorStandItem = CraftItemStack.asCraftMirror(itemstack);
+ org.bukkit.inventory.ItemStack playerHeldItem = CraftItemStack.asCraftMirror(itemstack);
+ org.bukkit.inventory.ItemStack playerHeldItem = CraftItemStack.asCraftMirror(p_31591_);
+
+ org.bukkit.entity.Player player = (org.bukkit.entity.Player) p_31589_.getBukkitEntity();
+ org.bukkit.entity.ArmorStand self = (org.bukkit.entity.ArmorStand) this.getBukkitEntity();
Expand All @@ -89,11 +76,10 @@
+ return true;
+ }
+
+ if (p_31589_.getAbilities().instabuild && itemstack.isEmpty() && !itemstack.isEmpty()) {
+ if (p_31589_.getAbilities().instabuild && itemstack.isEmpty() && !p_31591_.isEmpty()) {
+ // CraftBukkit end
+ this.setItemSlot(p_31590_, p_31591_.copyWithCount(1));
+ return true;
+ // CraftBukkit start
+ } else if (!p_31591_.isEmpty() && p_31591_.getCount() > 1) {
+ if (!itemstack.isEmpty()) {
+ return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.slf4j.Logger;

public abstract class HangingEntity extends Entity {
@@ -58,36 +_,46 @@
@@ -58,36 +_,47 @@

protected void recalculateBoundingBox() {
if (this.direction != null) {
Expand Down Expand Up @@ -57,6 +57,7 @@
+ // CraftBukkit end
+ }
+ }
+
+ // CraftBukkit start - break out BB calc into own method
+ public static AABB calculateBoundingBox(@Nullable Entity entity, BlockPos blockPosition, Direction direction, int width, int height) {
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,35 @@
this.dropItem(p_31776_.getEntity(), false);
this.gameEvent(GameEvent.BLOCK_CHANGE, p_31776_.getEntity());
this.playSound(this.getRemoveItemSound(), 1.0F, 1.0F);
@@ -274,14 +_,20 @@
@@ -274,6 +_,7 @@
this.setItem(p_31806_, true);
}

- public void setItem(ItemStack p_31790_, boolean p_31791_) {
+ public void setItem(ItemStack itemstack, boolean p_31791_) {
+ // CraftBukkit start
+ this.setItem(itemstack, p_31791_, true);
+ }
+
+ public void setItem(ItemStack p_31790_, boolean p_31791_, boolean playSound) {
+ // CraftBukkit end
+ //Ketting start - forge compat
public void setItem(ItemStack p_31790_, boolean p_31791_) {
if (!p_31790_.isEmpty()) {
p_31790_ = p_31790_.copyWithCount(1);
}
@@ -281,15 +_,22 @@

this.onItemChanged(p_31790_);
this.getEntityData().set(DATA_ITEM, p_31790_);
- if (!p_31790_.isEmpty()) {
+ if (!p_31790_.isEmpty() && playSound) { // CraftBukkit
+ if (!p_31790_.isEmpty() && setItem$playSound) { //Ketting
this.playSound(this.getAddItemSound(), 1.0F, 1.0F);
}

if (p_31791_ && this.pos != null) {
this.level().updateNeighbourForOutputSignal(this.pos, Blocks.AIR);
}
+ }

+ private boolean setItem$playSound = true;
+ public void setItem(ItemStack p_31790_, boolean p_31791_, boolean playSound) {
+ this.setItem$playSound = playSound;
+ this.setItem(p_31790_, p_31791_);
+ this.setItem$playSound = true;
}
+ //Ketting end

public SoundEvent getAddItemSound() {
return SoundEvents.ITEM_FRAME_ADD_ITEM;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class ItemEntity extends Entity implements TraceableEntity {
private static final EntityDataAccessor<ItemStack> DATA_ITEM = SynchedEntityData.defineId(ItemEntity.class, EntityDataSerializers.ITEM_STACK);
@@ -42,6 +_,11 @@
@@ -42,11 +_,18 @@
@Nullable
private UUID target;
public final float bobOffs;
Expand All @@ -30,11 +30,18 @@

public ItemEntity(EntityType<? extends ItemEntity> p_31991_, Level p_31992_) {
super(p_31991_, p_31992_);
this.bobOffs = this.random.nextFloat() * (float)Math.PI * 2.0F;
this.setYRot(this.random.nextFloat() * 360.0F);
+ if (lifespan == 6000) //Ketting - check if not modified
+ this.lifespan = (p_31992_.spigotConfig.itemDespawnRate); // Spigot
}

public ItemEntity(Level p_32001_, double p_32002_, double p_32003_, double p_32004_, ItemStack p_32005_) {
@@ -58,6 +_,7 @@
this.setPos(p_149664_, p_149665_, p_149666_);
this.setDeltaMovement(p_149668_, p_149669_, p_149670_);
this.setItem(p_149667_);
+ this.lifespan = (p_149667_.getItem() == null ? ItemEntity.LIFETIME : p_149667_.getEntityLifespan(p_149663_));
+ this.lifespan = (p_149667_.getItem() == null ? p_149663_.spigotConfig.itemDespawnRate : p_149667_.getEntityLifespan(p_149663_)); //Ketting - spigot
}

private ItemEntity(ItemEntity p_31994_) {
Expand Down Expand Up @@ -101,11 +108,16 @@

this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
if (!this.level().isClientSide) {
@@ -158,7 +_,22 @@
@@ -158,12 +_,62 @@
}
}

- if (!this.level().isClientSide && this.age >= 6000) {
- this.discard();
- }
-
- }
- }
+ ItemStack item = this.getItem();
+ if (!this.level().isClientSide && this.age >= lifespan) {
+ int hook = net.minecraftforge.event.ForgeEventFactory.onItemExpire(this, item);
Expand All @@ -122,9 +134,70 @@
+ }
+ }
+ if (item.isEmpty() && !this.isRemoved()) {
this.discard();
}
+ this.discard();
+ }
+
+ }
+ }
+
+ // Spigot start - copied from above
+ @Override
+ public void inactiveTick() {
+ // CraftBukkit start - Use wall time for pickup and despawn timers
+ int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
+ if (this.pickupDelay != 32767) this.pickupDelay -= elapsedTicks;
+ if (this.age != -32768) this.age += elapsedTicks;
+ this.lastTick = MinecraftServer.currentTick;
+ // CraftBukkit end
+
+ ItemStack item = this.getItem(); //Ketting
+ if (!this.level().isClientSide && this.age >= lifespan) { // Spigot
+ //Ketting start - forge event
+ int hook = net.minecraftforge.event.ForgeEventFactory.onItemExpire(this, item);
+ if (hook < 0) {
+ // CraftBukkit start - fire ItemDespawnEvent
+ if (CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
+ this.age = 0;
+ return;
+ }
+ // CraftBukkit end
+ this.discard();
+ } else {
+ this.lifespan += hook;
+ }
+ //Ketting end
+ }
+ //Ketting start
+ if (item.isEmpty() && !this.isRemoved()) {
+ this.discard();
+ }
+ //Ketting end
+ }
+ // Spigot end

protected BlockPos getBlockPosBelowThatAffectsMyMovement() {
return this.getOnPos(0.999999F);
@@ -181,7 +_,10 @@

private void mergeWithNeighbours() {
if (this.isMergable()) {
- for(ItemEntity itementity : this.level().getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(0.5D, 0.0D, 0.5D), (p_186268_) -> {
+ // Spigot start
+ double radius = this.level().spigotConfig.itemMerge;
+ for(ItemEntity itementity : this.level().getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(radius, radius - 0.5D, radius), (p_186268_) -> {
+ // Spigot end
return p_186268_ != this && p_186268_.isMergable();
})) {
if (itementity.isMergable()) {
@@ -204,7 +_,7 @@
ItemStack itemstack = this.getItem();
ItemStack itemstack1 = p_32016_.getItem();
if (Objects.equals(this.target, p_32016_.target) && areMergable(itemstack, itemstack1)) {
- if (itemstack1.getCount() < itemstack.getCount()) {
+ if (true || itemstack1.getCount() < itemstack.getCount()) { // Spigot
merge(this, itemstack, p_32016_, itemstack1);
} else {
merge(p_32016_, itemstack1, this, itemstack);
@@ -220,6 +_,8 @@
return false;
} else if (p_32028_.hasTag() ^ p_32027_.hasTag()) {
Expand All @@ -139,7 +212,7 @@

private static void merge(ItemEntity p_32018_, ItemStack p_32019_, ItemEntity p_32020_, ItemStack p_32021_) {
+ // CraftBukkit start
+ if (!CraftEventFactory.callItemMergeEvent(p_32018_, p_32020_)) {
+ if (!CraftEventFactory.callItemMergeEvent(p_32020_, p_32018_)) {
+ return;
+ }
+ // CraftBukkit end
Expand Down Expand Up @@ -182,7 +255,7 @@

if (p_32034_.hasUUID("Owner")) {
this.target = p_32034_.getUUID("Owner");
@@ -316,10 +_,56 @@
@@ -316,10 +_,58 @@

public void playerTouch(Player p_32040_) {
if (!this.level().isClientSide) {
Expand All @@ -193,6 +266,7 @@
- if (this.pickupDelay == 0 && (this.target == null || this.target.equals(p_32040_.getUUID())) && p_32040_.getInventory().add(itemstack)) {
+ int hook = net.minecraftforge.event.ForgeEventFactory.onItemPickup(this, p_32040_);
+ if (hook < 0) return;
+
+ // CraftBukkit start - fire PlayerPickupItemEvent
+ int canHold = p_32040_.getInventory().canHold(itemstack);
+ int remaining = i - canHold;
Expand Down Expand Up @@ -232,6 +306,7 @@
+ this.pickupDelay = -1;
+ }
+ // CraftBukkit end
+
+ ItemStack copy = itemstack.copy();
+ if (this.pickupDelay == 0 && (this.target == null || this.target.equals(p_32040_.getUUID())) && (hook == 1 || i <= 0 || p_32040_.getInventory().add(itemstack))) {
+ i = copy.getCount() - itemstack.getCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@

public PrimedTnt(EntityType<? extends PrimedTnt> p_32076_, Level p_32077_) {
super(p_32076_, p_32077_);
@@ -51,6 +_,7 @@
}

public void tick() {
+ if (this.level().spigotConfig.maxTntTicksPerTick > 0 && ++this.level().spigotConfig.currentPrimedTnt > this.level().spigotConfig.maxTntTicksPerTick) { return; } // Spigot
if (!this.isNoGravity()) {
this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.04D, 0.0D));
}
@@ -64,10 +_,13 @@
int i = this.getFuse() - 1;
this.setFuse(i);
Expand Down
Loading

0 comments on commit 71c5578

Please sign in to comment.