Classic funny

- When a Cake or Pie projectile launched from a Potato Cannon hits a mob, it will slide down the side of the target
This commit is contained in:
reidbhuntley 2021-07-06 21:22:52 -04:00
parent c14bece04d
commit 48ea7d64b4
4 changed files with 112 additions and 9 deletions

View file

@ -194,7 +194,35 @@ public class PotatoCannonProjectileTypes {
.renderTumbling()
.soundPitch(0.9f)
.onBlockHit(placeBlockOnGround(Blocks.PUMPKIN.delegate))
.registerAndAssign(Blocks.PUMPKIN)
.registerAndAssign(Blocks.PUMPKIN),
PUMPKIN_PIE = create("pumpkin_pie").damage(7)
.reloadTicks(15)
.knockback(0.05f)
.velocity(1.1f)
.renderTumbling()
.sticky()
.soundPitch(1.1f)
.registerAndAssign(Items.PUMPKIN_PIE),
CAKE = create("cake").damage(8)
.reloadTicks(15)
.knockback(0.1f)
.velocity(1.1f)
.renderTumbling()
.sticky()
.soundPitch(1.0f)
.registerAndAssign(Items.CAKE),
BLAZE_CAKE = create("blaze_cake").damage(12)
.reloadTicks(20)
.knockback(0.3f)
.velocity(1.1f)
.renderTumbling()
.sticky()
.onEntityHit(ray -> ray.getEntity().setFire(12))
.soundPitch(1.0f)
.registerAndAssign(AllItems.BLAZE_CAKE.get())
;
public static void registerType(ResourceLocation resLoc, PotatoCannonProjectileTypes type) {
@ -225,6 +253,7 @@ public class PotatoCannonProjectileTypes {
private int damage = 1;
private int split = 1;
private float fwoompPitch = 1;
private boolean sticky = false;
private PotatoProjectileRenderMode renderMode = new PotatoProjectileRenderMode.Billboard();
private Consumer<EntityRayTraceResult> onEntityHit = e -> {
};
@ -267,6 +296,8 @@ public class PotatoCannonProjectileTypes {
return damage;
}
public boolean isSticky() { return sticky; }
public void onEntityHit(EntityRayTraceResult ray) {
onEntityHit.accept(ray);
}
@ -445,6 +476,11 @@ public class PotatoCannonProjectileTypes {
return this;
}
public Builder sticky() {
result.sticky = true;
return this;
}
public Builder onEntityHit(Consumer<EntityRayTraceResult> callback) {
result.onEntityHit = callback;
return this;

View file

@ -36,6 +36,12 @@ import net.minecraftforge.fml.network.NetworkHooks;
public class PotatoProjectileEntity extends DamagingProjectileEntity implements IEntityAdditionalSpawnData {
ItemStack stack = ItemStack.EMPTY;
Entity stuckEntity;
Vector3d stuckOffset;
PotatoProjectileRenderMode stuckRenderer;
double stuckFallSpeed;
PotatoCannonProjectileTypes type;
public PotatoProjectileEntity(EntityType<? extends DamagingProjectileEntity> type, World world) {
@ -69,10 +75,48 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements
super.writeAdditional(nbt);
}
public Entity getStuckEntity() {
if (stuckEntity == null)
return null;
if (!stuckEntity.isAlive())
return null;
return stuckEntity;
}
public void setStuckEntity(Entity stuckEntity) {
this.stuckEntity = stuckEntity;
this.stuckOffset = getPositionVec().subtract(stuckEntity.getPositionVec());
this.stuckRenderer = new PotatoProjectileRenderMode.StuckToEntity(stuckOffset);
this.stuckFallSpeed = 0.0;
setMotion(Vector3d.ZERO);
}
public PotatoProjectileRenderMode getRenderMode() {
if (getStuckEntity() != null)
return stuckRenderer;
return getProjectileType().getRenderMode();
}
public void tick() {
PotatoCannonProjectileTypes projectileType = getProjectileType();
setMotion(getMotion().add(0, -.05 * projectileType.getGravityMultiplier(), 0)
.scale(projectileType.getDrag()));
Entity stuckEntity = getStuckEntity();
if (stuckEntity != null) {
if (getY() < stuckEntity.getY() - 0.1) {
pop(getPositionVec());
remove();
} else {
stuckFallSpeed += 0.007 * projectileType.getGravityMultiplier();
stuckOffset = stuckOffset.add(0, -stuckFallSpeed, 0);
Vector3d pos = stuckEntity.getPositionVec().add(stuckOffset);
setPosition(pos.x, pos.y, pos.z);
}
} else {
setMotion(getMotion().add(0, -0.05 * projectileType.getGravityMultiplier(), 0)
.scale(projectileType.getDrag()));
}
super.tick();
}
@ -95,6 +139,9 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements
protected void onEntityHit(EntityRayTraceResult ray) {
super.onEntityHit(ray);
if (getStuckEntity() != null)
return;
Vector3d hit = ray.getHitVec();
Entity target = ray.getEntity();
PotatoCannonProjectileTypes projectileType = getProjectileType();
@ -116,7 +163,8 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements
if (this.isBurning() && !targetIsEnderman)
target.setFire(5);
if (!target.attackEntityFrom(causePotatoDamage(), (float) damage)) {
boolean onServer = !world.isRemote;
if (onServer && !target.attackEntityFrom(causePotatoDamage(), (float) damage)) {
target.setFireTicks(k);
remove();
return;
@ -147,13 +195,12 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements
livingentity.addVelocity(appliedMotion.x, 0.1D, appliedMotion.z);
}
boolean onServer = !world.isRemote;
if (onServer && owner instanceof LivingEntity) {
EnchantmentHelper.applyThornEnchantments(livingentity, owner);
EnchantmentHelper.applyArthropodEnchantments((LivingEntity) owner, livingentity);
}
if (owner != null && livingentity != owner && livingentity instanceof PlayerEntity
if (livingentity != owner && livingentity instanceof PlayerEntity
&& owner instanceof ServerPlayerEntity && !this.isSilent()) {
((ServerPlayerEntity) owner).connection
.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.PROJECTILE_HIT_PLAYER, 0.0F));
@ -167,7 +214,12 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements
AllTriggers.POTATO_KILL.trigger(serverplayerentity);
}
remove();
if (type.isSticky() && target.isAlive()) {
setStuckEntity(target);
} else {
remove();
}
}
public static void playHitSound(World world, Vector3d location) {

View file

@ -72,6 +72,22 @@ public abstract class PotatoProjectileRenderMode {
}
public static class StuckToEntity extends PotatoProjectileRenderMode {
private Vector3d offset;
public StuckToEntity(Vector3d offset) {
this.offset = offset;
}
@Override
@OnlyIn(Dist.CLIENT)
public void transform(MatrixStack ms, PotatoProjectileEntity entity, float pt) {
MatrixStacker.of(ms).rotateY(AngleHelper.deg(MathHelper.atan2(offset.x, offset.z)));
}
}
public static int entityRandom(Entity entity, int maxValue) {
return (System.identityHashCode(entity) * 31) % maxValue;
}

View file

@ -26,8 +26,7 @@ public class PotatoProjectileRenderer extends EntityRenderer<PotatoProjectileEnt
ms.push();
ms.translate(0, entity.getBoundingBox()
.getYSize() / 2 - 1 / 8f, 0);
entity.getProjectileType()
.getRenderMode()
entity.getRenderMode()
.transform(ms, entity, pt);
Minecraft.getInstance()