Skip to content

Commit

Permalink
arrow improvements (ldtteam#9362)
Browse files Browse the repository at this point in the history
Make custom arrows not load
Small performance improvement of custom arrows
Despawn faster when in ground
  • Loading branch information
Raycoms committed Sep 7, 2023
1 parent 475375e commit 015eeeb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.minecolonies.coremod.entity;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Arrow;
import net.minecraft.network.protocol.Packet;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.NotNull;

import java.util.function.Predicate;

import net.minecraft.world.entity.Entity.RemovalReason;

/**
* Custom arrow entity class which remove themselves when on the ground for a bit to not cause lag and they do not scale in damage with their motion.
*/
Expand All @@ -26,6 +27,11 @@ public class CustomArrowEntity extends Arrow
*/
private static final int MAX_LIVE_TIME = 10 * 20;

/**
* Max time the arrow is stuck in ground before removing it.
*/
private static final int GROUND_LIVE_TIME = 2 * 20;

/**
* Whether the arrow entity pierces players
*/
Expand Down Expand Up @@ -117,13 +123,49 @@ public void setPlayerArmorPierce()
}

@Override
public void tick()
public boolean shouldFall()
{
super.tick();
if (this.inGround)
{
final AABB aabb = (new AABB(this.position(), this.position())).inflate(0.06D);
for(VoxelShape voxelshape : this.level.getBlockCollisions(null, aabb)) {
if (!voxelshape.isEmpty())
{
return false;
}
}
return true;
}
return false;
}

@Override
public boolean save(@NotNull CompoundTag nbt)
{
return false;
}

@Override
public void load(@NotNull CompoundTag nbt)
{
discard();
}

@Override
public void tick()
{
if (this.tickCount > MAX_LIVE_TIME)
{
remove(RemovalReason.DISCARDED);
return;
}

if (this.inGroundTime > GROUND_LIVE_TIME)
{
remove(RemovalReason.DISCARDED);
return;
}

super.tick();
}
}
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ public net.minecraft.world.level.block.state.BlockBehaviour$Properties f_60884_

public net.minecraft.client.gui.MapRenderer f_93255_ # textureManager

public net.minecraft.server.level.DistanceManager f_140761_ # tickets
public net.minecraft.server.level.DistanceManager f_140761_ # tickets
public net.minecraft.world.entity.projectile.AbstractArrow m_36798_()Z # shouldFall

0 comments on commit 015eeeb

Please sign in to comment.