mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-01 01:47:02 +01:00
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:
parent
c14bece04d
commit
48ea7d64b4
4 changed files with 112 additions and 9 deletions
|
@ -194,7 +194,35 @@ public class PotatoCannonProjectileTypes {
|
||||||
.renderTumbling()
|
.renderTumbling()
|
||||||
.soundPitch(0.9f)
|
.soundPitch(0.9f)
|
||||||
.onBlockHit(placeBlockOnGround(Blocks.PUMPKIN.delegate))
|
.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) {
|
public static void registerType(ResourceLocation resLoc, PotatoCannonProjectileTypes type) {
|
||||||
|
@ -225,6 +253,7 @@ public class PotatoCannonProjectileTypes {
|
||||||
private int damage = 1;
|
private int damage = 1;
|
||||||
private int split = 1;
|
private int split = 1;
|
||||||
private float fwoompPitch = 1;
|
private float fwoompPitch = 1;
|
||||||
|
private boolean sticky = false;
|
||||||
private PotatoProjectileRenderMode renderMode = new PotatoProjectileRenderMode.Billboard();
|
private PotatoProjectileRenderMode renderMode = new PotatoProjectileRenderMode.Billboard();
|
||||||
private Consumer<EntityRayTraceResult> onEntityHit = e -> {
|
private Consumer<EntityRayTraceResult> onEntityHit = e -> {
|
||||||
};
|
};
|
||||||
|
@ -267,6 +296,8 @@ public class PotatoCannonProjectileTypes {
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSticky() { return sticky; }
|
||||||
|
|
||||||
public void onEntityHit(EntityRayTraceResult ray) {
|
public void onEntityHit(EntityRayTraceResult ray) {
|
||||||
onEntityHit.accept(ray);
|
onEntityHit.accept(ray);
|
||||||
}
|
}
|
||||||
|
@ -445,6 +476,11 @@ public class PotatoCannonProjectileTypes {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder sticky() {
|
||||||
|
result.sticky = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder onEntityHit(Consumer<EntityRayTraceResult> callback) {
|
public Builder onEntityHit(Consumer<EntityRayTraceResult> callback) {
|
||||||
result.onEntityHit = callback;
|
result.onEntityHit = callback;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -36,6 +36,12 @@ import net.minecraftforge.fml.network.NetworkHooks;
|
||||||
public class PotatoProjectileEntity extends DamagingProjectileEntity implements IEntityAdditionalSpawnData {
|
public class PotatoProjectileEntity extends DamagingProjectileEntity implements IEntityAdditionalSpawnData {
|
||||||
|
|
||||||
ItemStack stack = ItemStack.EMPTY;
|
ItemStack stack = ItemStack.EMPTY;
|
||||||
|
|
||||||
|
Entity stuckEntity;
|
||||||
|
Vector3d stuckOffset;
|
||||||
|
PotatoProjectileRenderMode stuckRenderer;
|
||||||
|
double stuckFallSpeed;
|
||||||
|
|
||||||
PotatoCannonProjectileTypes type;
|
PotatoCannonProjectileTypes type;
|
||||||
|
|
||||||
public PotatoProjectileEntity(EntityType<? extends DamagingProjectileEntity> type, World world) {
|
public PotatoProjectileEntity(EntityType<? extends DamagingProjectileEntity> type, World world) {
|
||||||
|
@ -69,10 +75,48 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements
|
||||||
super.writeAdditional(nbt);
|
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() {
|
public void tick() {
|
||||||
PotatoCannonProjectileTypes projectileType = getProjectileType();
|
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();
|
super.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +139,9 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements
|
||||||
protected void onEntityHit(EntityRayTraceResult ray) {
|
protected void onEntityHit(EntityRayTraceResult ray) {
|
||||||
super.onEntityHit(ray);
|
super.onEntityHit(ray);
|
||||||
|
|
||||||
|
if (getStuckEntity() != null)
|
||||||
|
return;
|
||||||
|
|
||||||
Vector3d hit = ray.getHitVec();
|
Vector3d hit = ray.getHitVec();
|
||||||
Entity target = ray.getEntity();
|
Entity target = ray.getEntity();
|
||||||
PotatoCannonProjectileTypes projectileType = getProjectileType();
|
PotatoCannonProjectileTypes projectileType = getProjectileType();
|
||||||
|
@ -116,7 +163,8 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements
|
||||||
if (this.isBurning() && !targetIsEnderman)
|
if (this.isBurning() && !targetIsEnderman)
|
||||||
target.setFire(5);
|
target.setFire(5);
|
||||||
|
|
||||||
if (!target.attackEntityFrom(causePotatoDamage(), (float) damage)) {
|
boolean onServer = !world.isRemote;
|
||||||
|
if (onServer && !target.attackEntityFrom(causePotatoDamage(), (float) damage)) {
|
||||||
target.setFireTicks(k);
|
target.setFireTicks(k);
|
||||||
remove();
|
remove();
|
||||||
return;
|
return;
|
||||||
|
@ -147,13 +195,12 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements
|
||||||
livingentity.addVelocity(appliedMotion.x, 0.1D, appliedMotion.z);
|
livingentity.addVelocity(appliedMotion.x, 0.1D, appliedMotion.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean onServer = !world.isRemote;
|
|
||||||
if (onServer && owner instanceof LivingEntity) {
|
if (onServer && owner instanceof LivingEntity) {
|
||||||
EnchantmentHelper.applyThornEnchantments(livingentity, owner);
|
EnchantmentHelper.applyThornEnchantments(livingentity, owner);
|
||||||
EnchantmentHelper.applyArthropodEnchantments((LivingEntity) owner, livingentity);
|
EnchantmentHelper.applyArthropodEnchantments((LivingEntity) owner, livingentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (owner != null && livingentity != owner && livingentity instanceof PlayerEntity
|
if (livingentity != owner && livingentity instanceof PlayerEntity
|
||||||
&& owner instanceof ServerPlayerEntity && !this.isSilent()) {
|
&& owner instanceof ServerPlayerEntity && !this.isSilent()) {
|
||||||
((ServerPlayerEntity) owner).connection
|
((ServerPlayerEntity) owner).connection
|
||||||
.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.PROJECTILE_HIT_PLAYER, 0.0F));
|
.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.PROJECTILE_HIT_PLAYER, 0.0F));
|
||||||
|
@ -167,7 +214,12 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements
|
||||||
AllTriggers.POTATO_KILL.trigger(serverplayerentity);
|
AllTriggers.POTATO_KILL.trigger(serverplayerentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
remove();
|
if (type.isSticky() && target.isAlive()) {
|
||||||
|
setStuckEntity(target);
|
||||||
|
} else {
|
||||||
|
remove();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playHitSound(World world, Vector3d location) {
|
public static void playHitSound(World world, Vector3d location) {
|
||||||
|
|
|
@ -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) {
|
public static int entityRandom(Entity entity, int maxValue) {
|
||||||
return (System.identityHashCode(entity) * 31) % maxValue;
|
return (System.identityHashCode(entity) * 31) % maxValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ public class PotatoProjectileRenderer extends EntityRenderer<PotatoProjectileEnt
|
||||||
ms.push();
|
ms.push();
|
||||||
ms.translate(0, entity.getBoundingBox()
|
ms.translate(0, entity.getBoundingBox()
|
||||||
.getYSize() / 2 - 1 / 8f, 0);
|
.getYSize() / 2 - 1 / 8f, 0);
|
||||||
entity.getProjectileType()
|
entity.getRenderMode()
|
||||||
.getRenderMode()
|
|
||||||
.transform(ms, entity, pt);
|
.transform(ms, entity, pt);
|
||||||
|
|
||||||
Minecraft.getInstance()
|
Minecraft.getInstance()
|
||||||
|
|
Loading…
Reference in a new issue