Skip to content

Commit

Permalink
[2.0.0-rc.1] Fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Jan 31, 2022
1 parent 0cfc982 commit 2f8e1ff
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 6 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://api.modrinth.com/maven' }
maven { url 'https://jitpack.io' }
maven { url "https://maven.shedaniel.me/" }
maven {
name = "TerraformersMC"
url = "https://maven.terraformersmc.com/"
Expand Down Expand Up @@ -60,7 +61,7 @@ dependencies {
modImplementation include("eu.pb4:sgui:1.0.0-rc6+1.18-pre5")
modImplementation include("eu.pb4:hologram-api:0.2.1+1.18-pre5")
modImplementation include("eu.pb4:placeholder-api:1.1.3+1.17.1")
modImplementation include("eu.pb4:polymer:0.2.0-beta.20+1.18.1")
modImplementation include("eu.pb4:polymer:0.2.0-beta.21+1.18.1")
modImplementation include("fr.catcore:server-translations-api:1.4.8+1.18-pre1")
modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1G
fabric_version=0.44.0+1.18

# Mod Properties
mod_version = 2.0.0-beta.4.2+1.18.1
mod_version = 2.0.0-rc.1+1.18.1
maven_group = eu.pb4
archives_base_name = graves

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/eu/pb4/graves/GravesMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import eu.pb4.graves.other.Commands;
import eu.pb4.graves.other.VanillaInventoryMask;
import eu.pb4.polymer.api.block.PolymerBlockUtils;
import eu.pb4.polymer.api.entity.PolymerEntityUtils;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
Expand Down Expand Up @@ -43,6 +44,8 @@ public void onInitialize() {
Registry.register(Registry.ITEM, new Identifier("universal_graves", "icon"), IconItem.INSTANCE);
Registry.register(Registry.BLOCK, new Identifier("universal_graves", "grave"), GraveBlock.INSTANCE);
Registry.register(Registry.BLOCK, new Identifier("universal_graves", "visual_grave"), VisualGraveBlock.INSTANCE);
Registry.register(Registry.ENTITY_TYPE, new Identifier("universal_graves", "xp"), SafeXPEntity.TYPE);
PolymerEntityUtils.registerType(SafeXPEntity.TYPE);
GraveBlockEntity.BLOCK_ENTITY_TYPE = Registry.register(Registry.BLOCK_ENTITY_TYPE, "universal_graves:grave", FabricBlockEntityTypeBuilder.create(GraveBlockEntity::new, GraveBlock.INSTANCE).build(null));
VisualGraveBlockEntity.BLOCK_ENTITY_TYPE = Registry.register(Registry.BLOCK_ENTITY_TYPE, "universal_graves:visual_grave", FabricBlockEntityTypeBuilder.create(VisualGraveBlockEntity::new, VisualGraveBlock.INSTANCE).build(null));
Commands.register();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/eu/pb4/graves/config/data/ConfigData.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class ConfigData extends VersionedConfigData implements Cloneable {
public boolean replaceAnyBlock = false;
public int maxPlacementDistance = 8;
public boolean useRealTime = false;
public boolean useAlternativeXPEntity = FabricLoader.getInstance().isModLoaded("origins")
|| FabricLoader.getInstance().isModLoaded("bewitchment");

public boolean createFromPvP = true;
public boolean createFromVoid = true;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/eu/pb4/graves/grave/Grave.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import eu.pb4.graves.config.Config;
import eu.pb4.graves.config.ConfigManager;
import eu.pb4.graves.other.*;
import eu.pb4.graves.registry.SafeXPEntity;
import eu.pb4.graves.ui.GraveGui;
import eu.pb4.placeholders.PlaceholderAPI;
import me.lucko.fabric.api.permissions.v0.Permissions;
Expand Down Expand Up @@ -430,7 +431,7 @@ public void dropContent(MinecraftServer server) {
var chunk = world.getChunk(ChunkSectionPos.getSectionCoord(this.location.x()), ChunkSectionPos.getSectionCoord(this.location.z()));

ItemScatterer.spawn(world, this.location.blockPos(), this.asInventory());
ExperienceOrbEntity.spawn(world, Vec3d.ofCenter(this.location.blockPos()), this.xp);
GraveUtils.spawnExp(world, Vec3d.ofCenter(this.location.blockPos()), this.xp);
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/eu/pb4/graves/mixin/ExperienceOrbEntityAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eu.pb4.graves.mixin;

import net.minecraft.entity.ExperienceOrbEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(ExperienceOrbEntity.class)
public interface ExperienceOrbEntityAccessor {
@Accessor
void setAmount(int amount);
}
9 changes: 7 additions & 2 deletions src/main/java/eu/pb4/graves/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ private void replaceWithGrave(DamageSource source, CallbackInfo ci) {
placeholders2 = grave.getPlaceholders(player.getServer());
} else {
if (config.xpCalc != GravesXPCalculation.DROP) {
ExperienceOrbEntity.spawn(world, Vec3d.ofCenter(gravePos), finalExperience);
GraveUtils.spawnExp(world, Vec3d.ofCenter(gravePos), finalExperience);
}
text2 = config.creationFailedGraveMessage;
ItemScatterer.spawn(world, gravePos, DefaultedList.copyOf(ItemStack.EMPTY, items.toArray(new ItemStack[0])));
var droppedItems = DefaultedList.ofSize(0, ItemStack.EMPTY);
for (var item : items) {
droppedItems.add(item.stack());
}

ItemScatterer.spawn(world, gravePos, droppedItems);
((PlayerAdditions) player).graves_setLastGrave(-1);
}
if (text2 != null) {
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/eu/pb4/graves/other/GraveUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

import eu.pb4.graves.config.ConfigManager;
import eu.pb4.graves.event.GraveValidPosCheckEvent;
import eu.pb4.graves.registry.SafeXPEntity;
import net.fabricmc.fabric.api.tag.TagFactory;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -19,6 +21,7 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.border.WorldBorder;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -104,8 +107,16 @@ private static BlockCheckResult findPos(ServerPlayerEntity player, ServerWorld w
return new BlockCheckResult(null, result);
}

public static void spawnExp(ServerWorld world, Vec3d pos, int amount) {
if (ConfigManager.getConfig().configData.useAlternativeXPEntity) {
SafeXPEntity.spawn(world, pos, amount);
} else {
ExperienceOrbEntity.spawn(world, pos, amount);
}
}


private static BlockResult isValidPos(ServerPlayerEntity player, ServerWorld world, WorldBorder border, BlockPos pos, boolean anyBlock) {
private static BlockResult isValidPos(ServerPlayerEntity player, ServerWorld world, WorldBorder border, BlockPos pos, boolean anyBlock) {
BlockState state = world.getBlockState(pos);
if (border.contains(pos) && pos.getY() >= world.getBottomY() && pos.getY() < world.getTopY() && !state.hasBlockEntity() && (state.isAir() || anyBlock || REPLACEABLE_TAG.contains(state.getBlock()))) {
return GraveValidPosCheckEvent.EVENT.invoker().isValid(player, world, pos);
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/eu/pb4/graves/registry/SafeXPEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package eu.pb4.graves.registry;

import eu.pb4.graves.mixin.ExperienceOrbEntityAccessor;
import eu.pb4.polymer.api.entity.PolymerEntity;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class SafeXPEntity extends ExperienceOrbEntity implements PolymerEntity {
public static EntityType<Entity> TYPE = FabricEntityTypeBuilder.create().entityFactory(SafeXPEntity::new).fireImmune().disableSummon().dimensions(EntityDimensions.fixed(0.5F, 0.5F)).trackRangeChunks(6).trackedUpdateRate(20).build();
public SafeXPEntity(World world, double x, double y, double z, int amount) {
this(TYPE, world);
this.setPosition(x, y, z);
this.setYaw((float)(this.random.nextDouble() * 360.0D));
this.setVelocity((this.random.nextDouble() * 0.20000000298023224D - 0.10000000149011612D) * 2.0D, this.random.nextDouble() * 0.2D * 2.0D, (this.random.nextDouble() * 0.20000000298023224D - 0.10000000149011612D) * 2.0D);
((ExperienceOrbEntityAccessor) this).setAmount(amount);
}

public SafeXPEntity(EntityType<Entity> entityType, World world) {
super((EntityType<? extends ExperienceOrbEntity>) (Object) entityType, world);
}

public static void spawn(ServerWorld world, Vec3d pos, int amount) {
world.spawnEntity(new SafeXPEntity(world, pos.getX(), pos.getY(), pos.getZ(), amount));
}

@Override
public void onPlayerCollision(PlayerEntity player) {
if (!this.world.isClient) {
if (player.experiencePickUpDelay == 0) {
player.experiencePickUpDelay = 2;
player.sendPickup(this, 1);
player.addExperience(this.getExperienceAmount());
this.discard();
}
}
}

@Override
public EntityType<?> getPolymerEntityType() {
return EntityType.EXPERIENCE_BOTTLE;
}
}
1 change: 1 addition & 0 deletions src/main/resources/universal-graves.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "eu.pb4.graves.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"ExperienceOrbEntityAccessor",
"LivingEntityMixin",
"PlayerInventoryAccessor",
"ServerPlayerEntityMixin",
Expand Down

0 comments on commit 2f8e1ff

Please sign in to comment.