use of net.minecraftforge.eventbus.api.SubscribeEvent in project MinecraftForge by MinecraftForge.
the class GravityAttributeTest method worldTick.
@SubscribeEvent
public void worldTick(TickEvent.WorldTickEvent event) {
if (!event.world.isClientSide) {
if (ticks++ > 60) {
ticks = 0;
Level w = event.world;
List<LivingEntity> list;
if (w.isClientSide) {
ClientLevel cw = (ClientLevel) w;
list = new ArrayList<>(100);
for (Entity e : cw.entitiesForRendering()) {
if (e.isAlive() && e instanceof LivingEntity)
list.add((LivingEntity) e);
}
} else {
ServerLevel sw = (ServerLevel) w;
Stream<LivingEntity> s = StreamSupport.stream(sw.getEntities().getAll().spliterator(), false).filter(Entity::isAlive).filter(e -> e instanceof LivingEntity).map(e -> (LivingEntity) e);
list = s.collect(Collectors.toList());
}
for (LivingEntity liv : list) {
AttributeInstance grav = liv.getAttribute(ForgeMod.ENTITY_GRAVITY.get());
boolean inPlains = liv.level.getBiome(liv.blockPosition()).getBiomeCategory() == BiomeCategory.PLAINS;
if (inPlains && !grav.hasModifier(REDUCED_GRAVITY)) {
logger.info("Granted low gravity to Entity: {}", liv);
grav.addTransientModifier(REDUCED_GRAVITY);
} else if (!inPlains && grav.hasModifier(REDUCED_GRAVITY)) {
logger.info("Removed low gravity from Entity: {}", liv);
grav.removeModifier(REDUCED_GRAVITY);
}
}
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project BluePower by Qmunity.
the class BPEventHandler method onEntityAttack.
@SubscribeEvent
public void onEntityAttack(LivingAttackEvent event) {
if (!isAttacking && event.getSource() instanceof EntityDamageSource) {
// this event will be trigger recursively by EntityLiving#hurt,
// so we need to stop the loop.
EntityDamageSource entitySource = (EntityDamageSource) event.getSource();
if (entitySource.getEntity() instanceof PlayerEntity) {
PlayerEntity killer = (PlayerEntity) entitySource.getEntity();
if (!killer.inventory.getSelected().isEmpty()) {
if (EnchantmentHelper.getEnchantments(killer.inventory.getSelected()).containsKey(BPEnchantments.disjunction)) {
if (event.getEntityLiving() instanceof EndermanEntity || event.getEntityLiving() instanceof EnderDragonEntity) {
int level = EnchantmentHelper.getItemEnchantmentLevel(BPEnchantments.disjunction, killer.inventory.getSelected());
isAttacking = true;
event.getEntityLiving().hurt(event.getSource(), event.getAmount() * (level * 0.5F + 1));
isAttacking = false;
}
}
}
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project BluePower by Qmunity.
the class BPEventHandler method onAnvilEvent.
@SubscribeEvent
public void onAnvilEvent(AnvilUpdateEvent event) {
if (!event.getLeft().isEmpty() && event.getLeft().getItem() == BPItems.screwdriver) {
if (!event.getRight().isEmpty() && event.getRight().getItem() == Items.ENCHANTED_BOOK) {
if (EnchantmentHelper.getEnchantments(event.getRight()).get(Enchantments.SILK_TOUCH) != null) {
event.setOutput(new ItemStack(BPItems.silky_screwdriver, 1));
event.setCost(20);
}
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project BluePower by Qmunity.
the class BPEventHandler method itemPickUp.
@SubscribeEvent
public void itemPickUp(EntityItemPickupEvent event) {
PlayerEntity player = event.getPlayer();
ItemStack pickUp = event.getItem().getItem();
if (!(player.containerMenu instanceof ContainerSeedBag)) {
for (ItemStack is : player.inventory.items) {
if (!is.isEmpty() && is.getItem() instanceof ItemSeedBag) {
ItemStack seedType = ItemSeedBag.getSeedType(is);
if (!seedType.isEmpty() && seedType.sameItem(pickUp)) {
ItemStackHandler seedBagInvHandler = new ItemStackHandler(9);
// Get Items from the NBT Handler
if (is.hasTag())
seedBagInvHandler.deserializeNBT(is.getTag().getCompound("inv"));
// Attempt to insert items
for (int j = 0; j < 9 && !pickUp.isEmpty(); ++j) {
pickUp = seedBagInvHandler.insertItem(j, pickUp, false);
}
// Update items in the NBT
if (!is.hasTag())
is.setTag(new CompoundNBT());
if (is.getTag() != null) {
is.getTag().put("inv", seedBagInvHandler.serializeNBT());
}
// Pickup Leftovers
if (pickUp.isEmpty()) {
event.setResult(Event.Result.ALLOW);
event.getItem().remove();
return;
} else {
event.getItem().setItem(pickUp);
}
}
}
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project Tropicraft by Tropicraft.
the class PlayerRotationHandler method onRenderPlayer.
@SubscribeEvent
public static void onRenderPlayer(RenderPlayerEvent.Pre event) {
PoseStack stack = event.getMatrixStack();
MultiBufferSource buffers = event.getBuffers();
Player p = event.getPlayer();
Entity riding = p.getVehicle();
if (riding instanceof BeachFloatEntity) {
FurnitureEntity floaty = (FurnitureEntity) riding;
stack.pushPose();
stack.mulPose(Vector3f.YP.rotationDegrees(-(floaty.yRotO + (event.getPartialRenderTick() * (floaty.getYRot() - floaty.yRotO)))));
stack.translate(0, 1.55, 1.55);
stack.mulPose(Vector3f.XN.rotationDegrees(90));
// Cancel out player camera rotation
float f = interpolateAndWrap(p.yBodyRot, p.yBodyRotO, event.getPartialRenderTick());
stack.mulPose(Vector3f.YP.rotationDegrees(f));
// Lock in head
rotationYawHead = p.yHeadRot;
prevRotationYawHead = p.yHeadRotO;
p.yHeadRot = p.yBodyRot;
p.yHeadRotO = p.yBodyRotO;
rotationPitch = p.getXRot();
prevRotationPitch = p.xRotO;
p.setXRot(10f);
p.xRotO = 10f;
// Cancel limb swing
p.animationPosition = 0;
p.animationSpeed = 0;
p.animationSpeedOld = 0;
}
if (riding instanceof SeaTurtleEntity) {
SeaTurtleEntity turtle = (SeaTurtleEntity) riding;
stack.pushPose();
// Cancel out player camera rotation
float pitch = interpolateAndWrap(turtle.getXRot(), turtle.xRotO, event.getPartialRenderTick());
float yaw = interpolateAndWrap(turtle.yHeadRot, turtle.yHeadRotO, event.getPartialRenderTick());
stack.translate(0, turtle.getPassengersRidingOffset() - p.getMyRidingOffset(), 0);
stack.mulPose(Vector3f.YN.rotationDegrees(yaw));
// TODO figure out why this budging is needed
stack.translate(0, -0.1, 0);
stack.mulPose(Vector3f.XP.rotationDegrees(pitch));
stack.translate(0, 0.1, 0);
stack.mulPose(Vector3f.YP.rotationDegrees(yaw));
stack.translate(0, -turtle.getPassengersRidingOffset() + p.getMyRidingOffset(), 0);
Vec3 passengerOffset = (new Vec3(-0.25f, 0.0D, 0.0D)).yRot((float) (-Math.toRadians(yaw) - (Math.PI / 2)));
stack.translate(passengerOffset.x(), 0, passengerOffset.z());
// Lock in head
rotationPitch = p.getXRot();
prevRotationPitch = p.xRotO;
p.setXRot(10f);
p.xRotO = 10f;
}
}
Aggregations