use of net.minecraftforge.eventbus.api.SubscribeEvent in project NetherEx by LogicTechCorp.
the class PlayerHandler method onPlayerClone.
@SubscribeEvent
public static void onPlayerClone(PlayerEvent.Clone event) {
PlayerEntity oldPlayer = event.getOriginal();
PlayerEntity newPlayer = event.getPlayer();
IInventory oldInventory = oldPlayer.inventory;
IInventory newInventory = newPlayer.inventory;
if (event.isWasDeath()) {
ItemStack mirrorStack = ItemStack.EMPTY;
for (int i = 0; i < oldInventory.getSizeInventory(); i++) {
ItemStack stack = oldInventory.getStackInSlot(i);
if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
NBTHelper.ensureTagExists(stack);
if (stack.getTag().contains("SpawnPoint") && (stack.getDamage() < (stack.getMaxDamage() - 1))) {
stack.damageItem(1, newPlayer, entity -> {
});
}
newInventory.setInventorySlotContents(i, stack);
mirrorStack = stack;
break;
}
}
if (!mirrorStack.isEmpty()) {
if (mirrorStack.getDamage() < mirrorStack.getMaxDamage() - 1) {
CompoundNBT compound = NBTHelper.ensureTagExists(mirrorStack);
if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
if (spawnDimension != null) {
newPlayer.setSpawnDimenion(spawnDimension);
newPlayer.setSpawnPoint(spawnPoint, true, false, spawnDimension);
}
}
}
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project Overloaded by CJ-MC-Mods.
the class ItemRailGun method onMouseEvent.
@SubscribeEvent
public void onMouseEvent(InputEvent.MouseScrollEvent event) {
ClientPlayerEntity player = Minecraft.getInstance().player;
if (event.getScrollDelta() != 0 && player != null && player.isShiftKeyDown()) {
ItemStack stack = player.getMainHandItem();
if (player.isShiftKeyDown() && !stack.isEmpty() && stack.getItem() == this) {
int powerDelta = Long.signum(Math.round(event.getScrollDelta())) * OverloadedConfig.INSTANCE.railGun.stepEnergy;
if (InputMappings.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), ((ClientProxy) Overloaded.proxy).railGun100x.getKey().getValue())) {
powerDelta *= 100;
}
Overloaded.proxy.networkWrapper.sendToServer(new RailGunSettingsMessage(powerDelta));
event.setCanceled(true);
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project Overloaded by CJ-MC-Mods.
the class ArmorEventHandler method onLivingAttackedEvent.
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onLivingAttackedEvent(LivingAttackEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof PlayerEntity))
return;
PlayerEntity player = ((PlayerEntity) entity);
boolean setEquipped = isMultiArmorSetEquipped(player);
if (setEquipped) {
DamageSource damageSource = event.getSource();
int energyCost = OverloadedConfig.INSTANCE.multiArmorConfig.baseCost;
float damageAmount = (float) (event.getAmount() * OverloadedConfig.INSTANCE.multiArmorConfig.damageMultiplier);
if (damageSource.isBypassMagic())
damageAmount *= OverloadedConfig.INSTANCE.multiArmorConfig.absoluteDamageMultiplier;
if (damageSource.isBypassArmor())
damageAmount *= OverloadedConfig.INSTANCE.multiArmorConfig.unblockableMultiplier;
if (damageAmount > Integer.MAX_VALUE)
return;
energyCost += damageAmount;
// Overflow
if (energyCost < 0)
return;
if (extractEnergy(player, energyCost, false)) {
event.setCanceled(true);
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project Overloaded by CJ-MC-Mods.
the class ArmorEventHandler method onPlayerTickEvent.
@SubscribeEvent
public void onPlayerTickEvent(@Nonnull TickEvent.PlayerTickEvent event) {
PlayerEntity player = event.player;
if (player == null || player.dead)
return;
IGenericDataStorage playerDataStorage = getPlayerDataStorage(player);
if (isMultiArmorSetEquipped(player) && hasEnergy(player)) {
IGenericDataStorage armorDataStorage = getHelmetDataStorage(player);
Map<String, Boolean> armorBooleans = armorDataStorage.getBooleanMap();
playerDataStorage.getBooleanMap().put(set, true);
AttributeModifier modifier = player.getAttribute(Attributes.MAX_HEALTH).getModifier(HEALTH_MODIFIER);
if (modifier == null) {
player.getAttribute(Attributes.MAX_HEALTH).addTransientModifier(new AttributeModifier(HEALTH_MODIFIER, "Max Health", 100, AttributeModifier.Operation.ADDITION));
}
if (armorBooleans.getOrDefault(DataKeys.FLIGHT, Default.FLIGHT)) {
tryEnableFlight(player, playerDataStorage, armorDataStorage, event.side);
} else {
disableFlight(player, event.side);
}
if (armorBooleans.getOrDefault(DataKeys.FEED, Default.FEED)) {
tryFeedPlayer(player, event.side);
}
if (armorBooleans.getOrDefault(DataKeys.HEAL, Default.HEAL)) {
tryHealPlayer(player, event.side);
}
if (armorBooleans.getOrDefault(DataKeys.REMOVE_HARMFUL, Default.REMOVE_HARMFUL)) {
tryRemoveHarmful(player, event.side);
}
if (armorBooleans.getOrDefault(DataKeys.EXTINGUISH, Default.EXTINGUISH)) {
tryExtinguish(player, event.side);
}
if (armorBooleans.getOrDefault(DataKeys.GIVE_AIR, Default.GIVE_AIR)) {
tryGiveAir(player, event.side);
}
tryGroundSpeed(player, armorDataStorage, event.side);
} else {
Map<String, Boolean> boolMap = playerDataStorage.getBooleanMap();
if (boolMap.containsKey(set) && boolMap.get(set)) {
boolMap.put(set, false);
disableFlight(player, event.side);
disableNoClip(player, playerDataStorage);
disableGroundSpeed(player, event.side);
player.getAttribute(Attributes.MAX_HEALTH).removeModifier(HEALTH_MODIFIER);
player.setHealth(Math.min(player.getHealth(), player.getMaxHealth()));
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project Overloaded by CJ-MC-Mods.
the class ArmorEventHandler method onLivingUpdateEvent.
@SubscribeEvent
public void onLivingUpdateEvent(LivingEvent.LivingUpdateEvent event) {
Entity entity = event.getEntity();
if (entity instanceof PlayerEntity && isMultiArmorSetEquipped((PlayerEntity) entity)) {
PlayerEntity player = ((PlayerEntity) entity);
tryEnableNoClip(player, getPlayerDataStorage(player), getHelmetDataStorage(player), LogicalSide.SERVER);
}
}
Aggregations