Skip to content

Commit

Permalink
Fixed a couple of more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Feb 26, 2022
1 parent 23a4e0e commit 968da7a
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import javax.annotation.Nonnull;

@Mod.EventBusSubscriber(modid = Atum.MOD_ID, value = Dist.CLIENT)
public class RaArmorModel extends ArmorModel { //TODO Fix cape
public class RaArmorModel extends ArmorModel {
private boolean hasFullSet;
private final ModelPart leftBoot;
private final ModelPart rightBoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ protected void onHitEntity(EntityHitResult rayTrace) {
int fireTimer = entity.getRemainingFireTicks();

if (!(entity instanceof PharaohEntity) && entity.hurt(damagesource, (float) i)) {
if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
if (entity instanceof LivingEntity livingEntity) {

if (this.knockback > 0) {
Vec3 vector3d = this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale((double) this.knockback * 0.6D);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.init.AtumEntities;
import com.teammetallurgy.atum.init.AtumParticles;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
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.item.alchemy.Potions;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.network.PlayMessages;

public class ArrowStraightEntity extends CustomArrow {
Expand All @@ -28,7 +43,7 @@ public ArrowStraightEntity(Level world, LivingEntity shooter, float velocity) {

@Override
public void tick() {
super.tick();
this.arrowTick();

if (this.velocity == 1.0F) {
this.setDeltaMovement(this.getDeltaMovement().add(0.0D, 0.05D, 0.0D));
Expand All @@ -44,6 +59,188 @@ public void tick() {
}
}

public void arrowTick() {
this.abstractArrowTick();
if (this.level.isClientSide) {
if (this.inGround) {
if (this.inGroundTime % 5 == 0) {
this.makeParticle(1);
}
} else {
this.makeParticle(2);
}
} else if (this.inGround && this.inGroundTime != 0 && !this.effects.isEmpty() && this.inGroundTime >= 600) {
this.level.broadcastEntityEvent(this, (byte)0);
this.potion = Potions.EMPTY;
this.effects.clear();
this.entityData.set(ID_EFFECT_COLOR, -1);
}
}

private void makeParticle(int p_36877_) {
int i = this.getColor();
if (i != -1 && p_36877_ > 0) {
double d0 = (double)(i >> 16 & 255) / 255.0D;
double d1 = (double)(i >> 8 & 255) / 255.0D;
double d2 = (double)(i >> 0 & 255) / 255.0D;

for(int j = 0; j < p_36877_; ++j) {
this.level.addParticle(ParticleTypes.ENTITY_EFFECT, this.getRandomX(0.5D), this.getRandomY(), this.getRandomZ(0.5D), d0, d1, d2);
}

}
}

public void projectileTick() {
if (!this.hasBeenShot) {
this.gameEvent(GameEvent.PROJECTILE_SHOOT, this.getOwner(), this.blockPosition());
this.hasBeenShot = true;
}

if (!this.leftOwner) {
this.leftOwner = this.checkLeftOwner();
}

super.baseTick();
}

private boolean checkLeftOwner() {
Entity entity = this.getOwner();
if (entity != null) {
for(Entity entity1 : this.level.getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0D), (p_37272_) -> {
return !p_37272_.isSpectator() && p_37272_.isPickable();
})) {
if (entity1.getRootVehicle() == entity.getRootVehicle()) {
return false;
}
}
}

return true;
}

public void abstractArrowTick() {
this.projectileTick();
boolean flag = this.isNoPhysics();
Vec3 vec3 = this.getDeltaMovement();
if (this.xRotO == 0.0F && this.yRotO == 0.0F) {
double d0 = vec3.horizontalDistance();
this.setYRot((float)(Mth.atan2(vec3.x, vec3.z) * (double)(180F / (float)Math.PI)));
this.setXRot((float)(Mth.atan2(vec3.y, d0) * (double)(180F / (float)Math.PI)));
this.yRotO = this.getYRot();
this.xRotO = this.getXRot();
}

BlockPos blockpos = this.blockPosition();
BlockState blockstate = this.level.getBlockState(blockpos);
if (!blockstate.isAir() && !flag) {
VoxelShape voxelshape = blockstate.getCollisionShape(this.level, blockpos);
if (!voxelshape.isEmpty()) {
Vec3 vec31 = this.position();

for(AABB aabb : voxelshape.toAabbs()) {
if (aabb.move(blockpos).contains(vec31)) {
this.inGround = true;
break;
}
}
}
}

if (this.shakeTime > 0) {
--this.shakeTime;
}

if (this.isInWaterOrRain() || blockstate.is(Blocks.POWDER_SNOW)) {
this.clearFire();
}

if (this.inGround && !flag) {
if (this.lastState != blockstate && (this.inGround && this.level.noCollision((new AABB(this.position(), this.position())).inflate(0.06D)))) {
this.startFalling();
} else if (!this.level.isClientSide) {
this.tickDespawn();
}

++this.inGroundTime;
} else {
this.inGroundTime = 0;
Vec3 vec32 = this.position();
Vec3 vec33 = vec32.add(vec3);
HitResult hitresult = this.level.clip(new ClipContext(vec32, vec33, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this));
if (hitresult.getType() != HitResult.Type.MISS) {
vec33 = hitresult.getLocation();
}

while(!this.isRemoved()) {
EntityHitResult entityhitresult = this.findHitEntity(vec32, vec33);
if (entityhitresult != null) {
hitresult = entityhitresult;
}

if (hitresult != null && hitresult.getType() == HitResult.Type.ENTITY) {
Entity entity = ((EntityHitResult)hitresult).getEntity();
Entity entity1 = this.getOwner();
if (entity instanceof Player && entity1 instanceof Player && !((Player)entity1).canHarmPlayer((Player)entity)) {
hitresult = null;
entityhitresult = null;
}
}

if (hitresult != null && hitresult.getType() != HitResult.Type.MISS && !flag && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, hitresult)) {
this.onHit(hitresult);
this.hasImpulse = true;
}

if (entityhitresult == null || this.getPierceLevel() <= 0) {
break;
}

hitresult = null;
}

vec3 = this.getDeltaMovement();
double d5 = vec3.x;
double d6 = vec3.y;
double d1 = vec3.z;

//Removed crit particle

double d7 = this.getX() + d5;
double d2 = this.getY() + d6;
double d3 = this.getZ() + d1;
double d4 = vec3.horizontalDistance();
if (flag) {
this.setYRot((float)(Mth.atan2(-d5, -d1) * (double)(180F / (float)Math.PI)));
} else {
this.setYRot((float)(Mth.atan2(d5, d1) * (double)(180F / (float)Math.PI)));
}

this.setXRot((float)(Mth.atan2(d6, d4) * (double)(180F / (float)Math.PI)));
this.setXRot(lerpRotation(this.xRotO, this.getXRot()));
this.setYRot(lerpRotation(this.yRotO, this.getYRot()));
float f = 0.99F;
float f1 = 0.05F;
if (this.isInWater()) {
for(int j = 0; j < 4; ++j) {
float f2 = 0.25F;
this.level.addParticle(ParticleTypes.BUBBLE, d7 - d5 * 0.25D, d2 - d6 * 0.25D, d3 - d1 * 0.25D, d5, d6, d1);
}

f = this.getWaterInertia();
}

this.setDeltaMovement(vec3.scale((double)f));
if (!this.isNoGravity() && !flag) {
Vec3 vec34 = this.getDeltaMovement();
this.setDeltaMovement(vec34.x, vec34.y - (double)0.05F, vec34.z);
}

this.setPos(d7, d2, d3);
this.checkInsideBlocks();
}
}

@Override
public ResourceLocation getTexture() {
return new ResourceLocation(Atum.MOD_ID, "textures/arrow/arrow_straight.png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public CamelContainer(int windowID, Inventory playerInventory, final int entityI
//Saddle slot
this.addSlot(new Slot(camelInventory, 0, 62, 64) {
@Override
public boolean mayPlace(ItemStack stack) {
public boolean mayPlace(@Nonnull ItemStack stack) {
return stack.getItem() instanceof SaddleItem && !this.hasItem();
}
});
//Armor slot
this.addSlot(new Slot(camelInventory, 1, 80, 64) {
@Override
public boolean mayPlace(ItemStack stack) {
public boolean mayPlace(@Nonnull ItemStack stack) {
return camel.isArmor(stack);
}

Expand All @@ -58,7 +58,7 @@ public boolean isActive() {
//Carpet slot
this.addSlot(new Slot(camelInventory, 2, 98, 64) {
@Override
public boolean mayPlace(ItemStack stack) {
public boolean mayPlace(@Nonnull ItemStack stack) {
return camel.isValidCarpet(stack);
}

Expand All @@ -70,7 +70,7 @@ public int getMaxStackSize() {
//Left Crate slot
this.addSlot(new Slot(camelInventory, 3, 35, 64) {
@Override
public boolean mayPlace(ItemStack stack) {
public boolean mayPlace(@Nonnull ItemStack stack) {
return Block.byItem(stack.getItem()) instanceof CrateBlock;
}

Expand All @@ -81,7 +81,7 @@ public void setChanged() {
}

@Override
public boolean mayPickup(Player playerIn) {
public boolean mayPickup(@Nonnull Player player) {
for (Slot slot : leftCrateSlots) {
if (slot.hasItem()) {
return false;
Expand All @@ -98,7 +98,7 @@ public int getMaxStackSize() {
//Right Crate slot
this.addSlot(new Slot(camelInventory, 4, 125, 64) {
@Override
public boolean mayPlace(ItemStack stack) {
public boolean mayPlace(@Nonnull ItemStack stack) {
return Block.byItem(stack.getItem()) instanceof CrateBlock;
}

Expand All @@ -109,7 +109,7 @@ public void setChanged() {
}

@Override
public boolean mayPickup(Player playerIn) {
public boolean mayPickup(@Nonnull Player player) {
for (Slot slot : rightCrateSlots) {
if (slot.hasItem()) {
return false;
Expand Down Expand Up @@ -163,8 +163,9 @@ private void updateLeftChestSlots() {
}
}
if (!hasLeftSlots) {
for (int i = 0; i < leftCrateSlots.size(); i++) {
slots.add(camel.getNonCrateSize() + i, leftCrateSlots.get(i));
for (Slot leftCrateSlot : leftCrateSlots) {
slots.add(camel.getNonCrateSize() + leftCrateSlots.size(), leftCrateSlot);
remoteSlots.add(ItemStack.EMPTY);
lastSlots.add(ItemStack.EMPTY);
}
}
Expand All @@ -173,6 +174,7 @@ private void updateLeftChestSlots() {
Slot slot = slots.get(i);
if (leftCrateSlots.contains(slot)) {
slots.remove(i);
remoteSlots.remove(i);
lastSlots.remove(i);
i--;
}
Expand All @@ -195,6 +197,7 @@ private void updateRightChestSlots() {
if (!hasRightSlots) {
for (Slot rightCrateSlot : rightCrateSlots) {
slots.add(camel.getNonCrateSize() + leftCrateSlots.size(), rightCrateSlot);
remoteSlots.add(ItemStack.EMPTY);
lastSlots.add(ItemStack.EMPTY);
}
}
Expand All @@ -203,6 +206,7 @@ private void updateRightChestSlots() {
Slot slot = slots.get(i);
if (rightCrateSlots.contains(slot)) {
slots.remove(i);
remoteSlots.remove(i);
lastSlots.remove(i);
i--;
}
Expand All @@ -220,7 +224,7 @@ public boolean stillValid(@Nonnull Player player) {

@Override
@Nonnull
public ItemStack quickMoveStack(Player player, int index) {
public ItemStack quickMoveStack(@Nonnull Player player, int index) {
ItemStack stack = ItemStack.EMPTY;
Slot slot = this.slots.get(index);
if (slot != null && slot.hasItem()) {
Expand Down Expand Up @@ -264,7 +268,7 @@ public ItemStack quickMoveStack(Player player, int index) {
}

@Override
public void removed(Player player) {
public void removed(@Nonnull Player player) {
super.removed(player);
this.camelInventory.stopOpen(player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ private static void teleport(Level world, Entity entity, int x, int y, int z) {
}
}

private static void onTeleport(Level world, Entity entity) {
if (world instanceof ServerLevel) {
float timesRandom = world.random.nextFloat() * 4.0F;
float cosRandom = world.random.nextFloat() * ((float) Math.PI * 2F);
private static void onTeleport(Level level, Entity entity) {
if (level instanceof ServerLevel serverLevel) {
float timesRandom = serverLevel.random.nextFloat() * 4.0F;
float cosRandom = serverLevel.random.nextFloat() * ((float) Math.PI * 2F);
double x = Mth.cos(cosRandom) * timesRandom;
double y = 0.01D + (world.random.nextDouble() * 0.5D);
double y = 0.01D + (serverLevel.random.nextDouble() * 0.5D);
double z = Mth.sin(cosRandom) * timesRandom;
ServerLevel serverLevel = (ServerLevel) world;
BlockPos pos = entity.blockPosition();
serverLevel.sendParticles(AtumParticles.LIGHT_SPARKLE, entity.getX() + x * 0.1D, entity.getY() + 0.3D, entity.getZ() + z * 0.1D, 250, 0.25D, y, 0.25D, 0.005D);
serverLevel.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.SHULKER_TELEPORT, SoundSource.PLAYERS, 1.0F, 1.0F);
}
world.playSound(null, entity.blockPosition(), SoundEvents.SHULKER_TELEPORT, SoundSource.PLAYERS, 1.0F, 1.0F);
}
}

0 comments on commit 968da7a

Please sign in to comment.