Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakllp committed Oct 1, 2024
2 parents 786cdf2 + 9f4818c commit 7687236
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.bukkit.inventory.ItemStack;


@DefaultInfo(food = {"cactus"}, leashFlags = {"Tamed"})
@DefaultInfo(food = {"cactus"})
public interface MyCamel extends MyPet, MyPetBaby {
ItemStack getSaddle();

Expand Down
5 changes: 3 additions & 2 deletions modules/MyPet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<minecraft.version>1.20.6</minecraft.version>
<minecraft.version>1.21.1</minecraft.version>
<bukkit.packets>v1_8_R3;v1_9_R2;v1_12_R1;v1_16_R1;v1_16_R3;v1_17_R1;v1_18_R1;v1_18_R2;v1_19_R1;v1_19_R2;v1_19_R3;v1_20_R1;v1_20_R2;v1_20_R3;v1_20_R4;v1_21_R1</bukkit.packets>
<special.versions>1.19.2</special.versions>
</properties>
Expand Down Expand Up @@ -91,7 +91,8 @@
<finalName>${project.name}-${project.version}</finalName>
<archive>
<manifestEntries>
<Class-Path>MyPet/rhino.jar MyPet/rhino-1.7.9.jar MyPet/rhino-1.7.10.jar
<Class-Path>MyPet/rhino.jar MyPet/rhino-1.7.9.jar MyPet/rhino-1.7.10.jar MyPet/rhino-1.7.15.jar
../MyPet/rhino.jar ../MyPet/rhino-1.7.9.jar ../MyPet/rhino-1.7.10.jar ../MyPet/rhino-1.7.15.jar
MyPet/mongo-java-driver.jar MyPet/mongo-java-driver-3.12.11.jar
</Class-Path>
<Main-Class>de.Keyle.MyPet.skilltreecreator.Main</Main-Class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class JavaScriptExperienceCalculator implements ExperienceCalculator {
public JavaScriptExperienceCalculator() {
if (!new File(MyPetApi.getPlugin().getDataFolder(), "rhino.jar").exists() &&
!new File(MyPetApi.getPlugin().getDataFolder(), "rhino-1.7.9.jar").exists() &&
!new File(MyPetApi.getPlugin().getDataFolder(), "rhino-1.7.10.jar").exists()
!new File(MyPetApi.getPlugin().getDataFolder(), "rhino-1.7.10.jar").exists() &&
!new File(MyPetApi.getPlugin().getDataFolder(), "rhino-1.7.15.jar").exists()
) {
MyPetApi.getLogger().warning("rhino.jar is missing. Please download it here (https://github.com/mozilla/rhino/releases) and put it into the MyPet folder.");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;

@PluginHookName("ProtocolLib")
Expand Down Expand Up @@ -155,6 +157,9 @@ public void onPacketReceiving(PacketEvent event) {
if(ent != null) {
packet.getIntegers().write(0, ent.getEntityId());
}
} catch (TimeoutException e) {
// Assume the main thread is blocked and should free this netty thread.
return;
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -163,11 +168,12 @@ public void onPacketReceiving(PacketEvent event) {
});
}

private <T> T ensureMainThread(Supplier<T> supplier) throws ExecutionException, InterruptedException {
private <T> T ensureMainThread(Supplier<T> supplier) throws ExecutionException, InterruptedException, TimeoutException {
if(Bukkit.isPrimaryThread()) {
return supplier.get();
} else {
return Bukkit.getServer().getScheduler().callSyncMethod(MyPetApi.getPlugin(), supplier::get).get();
return Bukkit.getServer().getScheduler().callSyncMethod(MyPetApi.getPlugin(), supplier::get)
.get(100, TimeUnit.MILLISECONDS);
}
}

Expand Down Expand Up @@ -211,7 +217,10 @@ public void onPacketSending(PacketEvent event) {
if(MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.17") >= 0) { //1.17+ does not like async
try {
entity = ensureMainThread(() -> MyPetApi.getPlatformHelper().getEntity(id, event.getPlayer().getWorld()));
} catch (Exception e) {
} catch (TimeoutException e) {
// Assume the main thread is blocked and should free this netty thread.
return;
} catch (Exception e) {
e.printStackTrace();
}
} else {
Expand Down Expand Up @@ -264,4 +273,4 @@ public void onPacketSending(PacketEvent event) {
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,15 @@ protected void defineSynchedData(SynchedEntityData.Builder builder) {
super.defineSynchedData(builder);
builder.define(AGE_WATCHER, false);
builder.define(SADDLE_CHEST_WATCHER, (byte) 0);
builder.define(DASH, false);

builder.define(LAST_POSE_CHANGE_TICK, (long)0);
resetLastPoseChangeTickToFullStand(this.level().getGameTime());
}
private void resetLastPoseChangeTickToFullStand(long i) {
this.resetLastPoseChangeTick(Math.max(0L, i - 52L - 1L));
builder.define(LAST_POSE_CHANGE_TICK, Math.max(0L, this.level().getGameTime() - 52L - 1L));
}
private void resetLastPoseChangeTick(long i) {
entityData.set(LAST_POSE_CHANGE_TICK, i);
this.getEntityData().set(LAST_POSE_CHANGE_TICK, i);
}
public long getPoseTime() {
return this.level().getGameTime() - Math.abs((Long) this.entityData.get(LAST_POSE_CHANGE_TICK));
return this.level().getGameTime() - Math.abs((Long) this.getEntityData().get(LAST_POSE_CHANGE_TICK));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import de.Keyle.MyPet.api.entity.EntitySize;
import de.Keyle.MyPet.api.entity.MyPet;
import de.Keyle.MyPet.api.entity.types.MyTraderLlama;
import de.Keyle.MyPet.compat.v1_20_R4.CompatManager;
import de.Keyle.MyPet.compat.v1_20_R4.entity.EntityMyPet;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
Expand All @@ -37,21 +36,17 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.WoolCarpetBlock;
import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack;

import java.lang.reflect.InvocationTargetException;

@EntitySize(width = 0.9F, height = 1.87F)
public class EntityMyTraderLlama extends EntityMyPet {

private static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Byte> SADDLE_CHEST_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.BYTE);
private static final EntityDataAccessor<Boolean> CHEST_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Integer> STRENGTH_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Integer> COLOR_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.INT);
//private static final EntityDataAccessor<Integer> COLOR_WATCHER = SynchedEntityData.defineId(EntityMyLlama.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Integer> VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.INT);

public EntityMyTraderLlama(Level world, MyPet myPet) {
Expand All @@ -73,7 +68,6 @@ protected String getLivingSound() {
return "entity.llama.ambient";
}


@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
Expand Down Expand Up @@ -146,22 +140,22 @@ protected void defineSynchedData(SynchedEntityData.Builder builder) {
builder.define(SADDLE_CHEST_WATCHER, (byte) 0); // saddle & chest
builder.define(CHEST_WATCHER, false);
builder.define(STRENGTH_WATCHER, 0);
builder.define(COLOR_WATCHER, 0);
//builder.define(COLOR_WATCHER, 0);
builder.define(VARIANT_WATCHER, 0);
}

@Override
public void updateVisuals() {
this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest());
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if (getMyPet().hasDecor()) {
/*if (getMyPet().hasDecor()) {
ItemStack is = CraftItemStack.asNMSCopy(getMyPet().getDecor());
Block block = Block.byItem(is.getItem());
int color = block instanceof WoolCarpetBlock ? ((WoolCarpetBlock) block).getColor().getId() : 0;
this.getEntityData().set(COLOR_WATCHER, color);
} else {
this.getEntityData().set(COLOR_WATCHER, -1);
}
}*/
this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ public void setArrowsInBody(int i) {
public EntityEquipment getEquipment() {
return fakeEquipment;
}


@Override
public void setRiptiding(boolean b) {
}

@Override
public void attack(@NotNull Entity entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,15 @@ protected void defineSynchedData(SynchedEntityData.Builder builder) {
super.defineSynchedData(builder);
builder.define(AGE_WATCHER, false);
builder.define(SADDLE_CHEST_WATCHER, (byte) 0);
builder.define(DASH, false);

builder.define(LAST_POSE_CHANGE_TICK, (long)0);
resetLastPoseChangeTickToFullStand(this.level().getGameTime());
}
private void resetLastPoseChangeTickToFullStand(long i) {
this.resetLastPoseChangeTick(Math.max(0L, i - 52L - 1L));
builder.define(LAST_POSE_CHANGE_TICK, Math.max(0L, this.level().getGameTime() - 52L - 1L));
}
private void resetLastPoseChangeTick(long i) {
entityData.set(LAST_POSE_CHANGE_TICK, i);
this.getEntityData().set(LAST_POSE_CHANGE_TICK, i);
}
public long getPoseTime() {
return this.level().getGameTime() - Math.abs((Long) this.entityData.get(LAST_POSE_CHANGE_TICK));
return this.level().getGameTime() - Math.abs((Long) this.getEntityData().get(LAST_POSE_CHANGE_TICK));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import de.Keyle.MyPet.api.entity.EntitySize;
import de.Keyle.MyPet.api.entity.MyPet;
import de.Keyle.MyPet.api.entity.types.MyTraderLlama;
import de.Keyle.MyPet.compat.v1_21_R1.CompatManager;
import de.Keyle.MyPet.compat.v1_21_R1.entity.EntityMyPet;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
Expand All @@ -37,21 +36,17 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.WoolCarpetBlock;
import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack;

import java.lang.reflect.InvocationTargetException;

@EntitySize(width = 0.9F, height = 1.87F)
public class EntityMyTraderLlama extends EntityMyPet {

private static final EntityDataAccessor<Boolean> AGE_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Byte> SADDLE_CHEST_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.BYTE);
private static final EntityDataAccessor<Boolean> CHEST_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Integer> STRENGTH_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Integer> COLOR_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.INT);
//private static final EntityDataAccessor<Integer> COLOR_WATCHER = SynchedEntityData.defineId(EntityMyLlama.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Integer> VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.INT);

public EntityMyTraderLlama(Level world, MyPet myPet) {
Expand All @@ -73,7 +68,6 @@ protected String getLivingSound() {
return "entity.llama.ambient";
}


@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
Expand Down Expand Up @@ -146,22 +140,22 @@ protected void defineSynchedData(SynchedEntityData.Builder builder) {
builder.define(SADDLE_CHEST_WATCHER, (byte) 0); // saddle & chest
builder.define(CHEST_WATCHER, false);
builder.define(STRENGTH_WATCHER, 0);
builder.define(COLOR_WATCHER, 0);
//builder.define(COLOR_WATCHER, 0);
builder.define(VARIANT_WATCHER, 0);
}

@Override
public void updateVisuals() {
this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest());
this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
if (getMyPet().hasDecor()) {
/*if (getMyPet().hasDecor()) {
ItemStack is = CraftItemStack.asNMSCopy(getMyPet().getDecor());
Block block = Block.byItem(is.getItem());
int color = block instanceof WoolCarpetBlock ? ((WoolCarpetBlock) block).getColor().getId() : 0;
this.getEntityData().set(COLOR_WATCHER, color);
} else {
this.getEntityData().set(COLOR_WATCHER, -1);
}
}*/
this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant());
}

Expand Down

0 comments on commit 7687236

Please sign in to comment.