Skip to content

Commit

Permalink
tweaked stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Globox1997 committed Nov 21, 2023
1 parent 28964ab commit 10e6d8f
Show file tree
Hide file tree
Showing 18 changed files with 316 additions and 395 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Added:
-
- Added SpoiledZ compat
### Fixed:
-
### Changed:
- Updated to mc 1.20.1
- Tweaked internals
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

loom {
accessWidenerPath = file("src/main/resources/rpgz.aw")
}

repositories {
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/" }
maven { url "https://api.modrinth.com/maven" }
}

dependencies {
Expand All @@ -30,6 +27,12 @@ dependencies {
modCompileOnly modRuntimeOnly("com.terraformersmc:modmenu:${project.mod_menu_version}"),{
exclude(group: "net.fabricmc.fabric-api")
}
// Extras
include(modImplementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:0.2.0")))
// SpoiledZ
modCompileOnly ('maven.modrinth:spoiledz:1.0.8+1.20.1') {
exclude(group: "net.fabricmc.fabric-api")
}
}

processResources {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://fabricmc.net/use
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.14.21
loader_version=0.14.24

# Mod Properties
mod_version=0.5.3
Expand All @@ -13,6 +13,6 @@ org.gradle.jvmargs=-Xmx1G

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.86.0+1.20.1
fabric_version=0.90.7+1.20.1
cloth_config_version=11.0.99
mod_menu_version=7.0.0
2 changes: 1 addition & 1 deletion src/main/java/net/rpgz/access/InventoryAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public interface InventoryAccess {

public SimpleInventory getInventory();

public void addingInventoryItems(ItemStack stack);
public void addInventoryItem(ItemStack stack);
}
218 changes: 2 additions & 216 deletions src/main/java/net/rpgz/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,252 +1,38 @@
package net.rpgz.mixin;

import java.util.stream.StreamSupport;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import org.spongepowered.asm.mixin.injection.At;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.FlyingEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShovelItem;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.context.LootContextParameterSet;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.World;
import net.rpgz.access.InventoryAccess;
import net.rpgz.init.ConfigInit;
import net.rpgz.init.TagInit;
import net.rpgz.ui.LivingEntityScreenHandler;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity implements InventoryAccess {
@Shadow
public int deathTime;
@Shadow
public float bodyYaw;
@Shadow
protected int playerHitTimer;
public abstract class LivingEntityMixin implements InventoryAccess {

private final boolean isEntityInstanceOfMobEnity = (Object) this instanceof MobEntity;

public SimpleInventory inventory = new SimpleInventory(9);

public LivingEntityMixin(EntityType<? extends LivingEntity> entityType, World world) {
super(entityType, world);
}

@Inject(method = "tickMovement", at = @At("HEAD"), cancellable = true)
private void tickMovementMixin(CallbackInfo info) {
LivingEntity livingEntity = (LivingEntity) (Object) this;
if (this.deathTime > 19 && isEntityInstanceOfMobEnity) {
Box box = this.getBoundingBox();
BlockPos blockPos = BlockPos.ofFloored(box.getCenter().getX(), box.minY, box.getCenter().getZ());
if (this.getWorld().getBlockState(blockPos).isAir()) {
if (livingEntity instanceof FlyingEntity) {
this.setPos(this.getX(), this.getY() - 0.25D, this.getZ());
} else if (this.getVelocity().y > 0) {
this.setPos(this.getX(), this.getY() - (this.getVelocity().y > 0.8D ? 0.8D : this.getVelocity().y), this.getZ());
} else if (this.getVelocity().y < 0) {
this.setPos(this.getX(), this.getY() + (this.getVelocity().y < -0.8D ? -0.8D : this.getVelocity().y) + (this.getVelocity().y > -0.2D ? -0.4D : 0.0D), this.getZ());
} else {
this.setPos(this.getX(), this.getY() - 0.1D, this.getZ());
}
} else
// Water floating
if (this.getWorld().containsFluid(box.offset(0.0D, box.getYLength(), 0.0D))) {
if (ConfigInit.CONFIG.surfacing_in_water)
this.setPos(this.getX(), this.getY() + 0.03D, this.getZ());
if (this.canWalkOnFluid(this.getWorld().getFluidState(this.getBlockPos())))
this.setPos(this.getX(), this.getY() + 0.03D, this.getZ());
else if (this.getWorld().containsFluid(box.offset(0.0D, -box.getYLength() + (box.getYLength() / 5), 0.0D)) && !ConfigInit.CONFIG.surfacing_in_water)
this.setPos(this.getX(), this.getY() - 0.05D, this.getZ());
}
info.cancel();
}

}

@SuppressWarnings("deprecation")
@Inject(method = "updatePostDeath", at = @At("HEAD"), cancellable = true)
protected void updatePostDeathMixin(CallbackInfo info) {
if (isEntityInstanceOfMobEnity) {
++this.deathTime;
if (this.deathTime == 1) {
if (this.isOnFire())
this.extinguish();
if (this.getVehicle() != null)
this.stopRiding();
}

if (this.deathTime >= 20) {
// Has to get set on server and client
Box newBoundingBox = new Box(this.getX() - (this.getWidth() / 3.0F), this.getY() - (this.getWidth() / 3.0F), this.getZ() - (this.getWidth() / 3.0F),
this.getX() + (this.getWidth() / 1.5F), this.getY() + (this.getWidth() / 1.5F), this.getZ() + (this.getWidth() / 1.5F));
if ((this.getDimensions(EntityPose.STANDING).height < 1.0F && this.getDimensions(EntityPose.STANDING).width < 1.0F)
|| (this.getDimensions(EntityPose.STANDING).width / this.getDimensions(EntityPose.STANDING).height) > 1.395F) {
this.setBoundingBox(newBoundingBox);
} else {
this.setBoundingBox(newBoundingBox.offset(this.getRotationVector(0F, this.bodyYaw).rotateY(-30.0F)));
// this.setBoundingBox(newBoundingBox.offset(this.getRotationVecClient().rotateY(-30.0F)));
// acceptable solution
}
// Chicken always has trouble - not fixable
// Shulker has trouble
// this.checkBlockCollision(); //Doesnt solve problem
// if (this.isInsideWall()) {} // Doenst work
if (!this.getWorld().isClient()) {
Box box = this.getBoundingBox();
BlockPos blockPos = BlockPos.ofFloored(box.minX + 0.001D, box.minY + 0.001D, box.minZ + 0.001D).up();
BlockPos blockPos2 = BlockPos.ofFloored(box.maxX - 0.001D, box.maxY - 0.001D, box.maxZ - 0.001D);

// Older method, might be better?
// if (this.getWorld().isRegionLoaded(blockPos, blockPos2)) {
// if (!world.isClient && !this.inventory.isEmpty()
// && (world.getBlockState(blockPos).isFullCube(world, blockPos)
// || world.getBlockState(blockPos2).isFullCube(world, blockPos2) ||
// this.isBaby()
// || (Config.CONFIG.drop_unlooted && this.deathTime >
// Config.CONFIG.drop_after_ticks))
// || this.getType().isIn(Tags.EXCLUDED_ENTITIES)
// ||
// Config.CONFIG.excluded_entities.contains(this.getType().toString().replace("entity.",
// ""))) {
// this.inventory.clearToList().forEach(this::dropStack);
// }
// }

// New method to check if inside block
Box checkBox = new Box(box.maxX, box.maxY, box.maxZ, box.maxX + 0.001D, box.maxY + 0.001D, box.maxZ + 0.001D);
Box checkBoxTwo = new Box(box.minX, box.maxY, box.minZ, box.minX + 0.001D, box.maxY + 0.001D, box.minZ + 0.001D);
Box checkBoxThree = new Box(box.maxX - (box.getXLength() / 3D), box.maxY, box.maxZ - (box.getZLength() / 3D), box.maxX + 0.001D - (box.getXLength() / 3D), box.maxY + 0.001D,
box.maxZ + 0.001D - (box.getZLength() / 3D));
if (this.getWorld().isRegionLoaded(blockPos, blockPos2))
if (!this.inventory.isEmpty()
&& (((!StreamSupport.stream(this.getWorld().getBlockCollisions(this, checkBox).spliterator(), false).allMatch(VoxelShape::isEmpty)
|| !StreamSupport.stream(this.getWorld().getBlockCollisions(this, checkBoxThree).spliterator(), false).allMatch(VoxelShape::isEmpty))
&& (!StreamSupport.stream(this.getWorld().getBlockCollisions(this, checkBoxTwo).spliterator(), false).allMatch(VoxelShape::isEmpty)
|| !StreamSupport.stream(this.getWorld().getBlockCollisions(this, checkBoxThree).spliterator(), false).allMatch(VoxelShape::isEmpty)))
|| this.isBaby() || (ConfigInit.CONFIG.drop_unlooted && this.deathTime > ConfigInit.CONFIG.drop_after_ticks))
|| this.getType().isIn(TagInit.EXCLUDED_ENTITIES) || ConfigInit.CONFIG.excluded_entities.contains(this.getType().toString().replace("entity.", "").replace(".", ":")))

this.inventory.clearToList().forEach(this::dropStack);
}
// world.getClosestPlayer(this,// 1.0D)// !=// null// || Testing purpose
}

if ((!this.getWorld().isClient() && this.deathTime >= 20 && this.inventory.isEmpty() && ConfigInit.CONFIG.despawn_immediately_when_empty)
|| (this.deathTime >= ConfigInit.CONFIG.despawn_corps_after_ticks)) {
if (!this.getWorld().isClient()) // Make sure only on server particle
this.despawnParticlesServer();

this.remove(RemovalReason.KILLED);
}
info.cancel();
}
}

private void despawnParticlesServer() {
for (int i = 0; i < 20; ++i) {
double d = this.random.nextGaussian() * 0.025D;
double e = this.random.nextGaussian() * 0.025D;
double f = this.random.nextGaussian() * 0.025D;
double x = MathHelper.nextDouble(random, this.getBoundingBox().minX - 0.5D, this.getBoundingBox().maxX) + 0.5D;
double y = MathHelper.nextDouble(random, this.getBoundingBox().minY, this.getBoundingBox().maxY) + 0.5D;
double z = MathHelper.nextDouble(random, this.getBoundingBox().minZ - 0.5D, this.getBoundingBox().maxZ) + 0.5D;
((ServerWorld) this.getWorld()).spawnParticles(ParticleTypes.POOF, x, y, z, 0, d, e, f, 0.01D);
}
}

// generateLoot
@Inject(method = "dropLoot", at = @At(value = "INVOKE", target = "Lnet/minecraft/loot/LootTable;generateLoot(Lnet/minecraft/loot/context/LootContextParameterSet;JLjava/util/function/Consumer;)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT)
private void dropLootMixin(DamageSource source, boolean causedByPlayer, CallbackInfo info, Identifier identifier, LootTable lootTable, LootContextParameterSet.Builder builder,
LootContextParameterSet lootContextParameterSet) {
if (isEntityInstanceOfMobEnity) {
lootTable.generateLoot(lootContextParameterSet, this.getLootTableSeed(), this::addingInventoryItems);
lootTable.generateLoot(lootContextParameterSet, this.getLootTableSeed(), this::addInventoryItem);
info.cancel();
}

}

@Override
public void addingInventoryItems(ItemStack stack) {
if (!this.getWorld().isClient() && !stack.isEmpty())
this.inventory.addStack(stack);
}

@Override
public ActionResult interactAt(PlayerEntity player, Vec3d hitPos, Hand hand) {
if (this.deathTime > 20) {
if (!this.getWorld().isClient()) {
if (player.getStackInHand(hand).getItem() instanceof ShovelItem) {
if (!this.inventory.isEmpty())
for (int i = 0; i < this.inventory.size(); i++)
player.getInventory().offerOrDrop(this.inventory.getStack(i));
this.inventory.clear();
if (!ConfigInit.CONFIG.despawn_immediately_when_empty) {
this.despawnParticlesServer();
this.remove(RemovalReason.KILLED);
}
return ActionResult.SUCCESS;
}
if (!this.inventory.isEmpty()) {
if (player.isSneaking()) {
for (int i = 0; i < this.inventory.size(); i++)
player.getInventory().offerOrDrop(this.inventory.getStack(i));
this.inventory.clear();
} else
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, inv, p) -> new LivingEntityScreenHandler(syncId, p.getInventory(), this.inventory), Text.literal("")));
return ActionResult.SUCCESS;
}
} else if ((Object) this instanceof PlayerEntity) {
return super.interactAt(player, hitPos, hand);
}
return ActionResult.SUCCESS;
}
return super.interactAt(player, hitPos, hand);
}

@Shadow
public long getLootTableSeed() {
return 0L;
}

@Shadow
public boolean canWalkOnFluid(FluidState fluidState) {
return false;
}

@Shadow
public boolean isBaby() {
return false;
}

@Override
public SimpleInventory getInventory() {
return this.inventory;
}

}
Loading

0 comments on commit 10e6d8f

Please sign in to comment.