use of me.deecaad.weaponmechanics.wrappers.ZoomData in project MechanicsMain by WeaponMechanics.
the class ScopeHandler method tryUse.
/**
* Tries to use scope
*
* @param entityWrapper the entity who used trigger
* @param weaponTitle the weapon title
* @param weaponStack the weapon stack
* @param slot the slot used on trigger
* @param triggerType the trigger type trying to activate scope
* @return true if the scope used successfully to zoom in, our or stack
*/
public boolean tryUse(EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, EquipmentSlot slot, TriggerType triggerType, boolean dualWield) {
Configuration config = getConfigurations();
// Don't try to scope if either one of the hands is reloading
if (entityWrapper.getMainHandData().isReloading() || entityWrapper.getOffHandData().isReloading()) {
return false;
}
ZoomData zoomData;
// Only allow using zoom at one hand at time
if (slot == EquipmentSlot.HAND) {
if (entityWrapper.getOffHandData().getZoomData().isZooming()) {
return false;
}
zoomData = entityWrapper.getMainHandData().getZoomData();
} else {
if (entityWrapper.getMainHandData().getZoomData().isZooming()) {
return false;
}
zoomData = entityWrapper.getOffHandData().getZoomData();
}
Trigger trigger = config.getObject(weaponTitle + ".Scope.Trigger", Trigger.class);
if (trigger == null)
return false;
// Check if entity is already zooming
if (zoomData.isZooming()) {
Trigger offTrigger = config.getObject(weaponTitle + ".Scope.Zoom_Off.Trigger", Trigger.class);
// If off trigger is valid -> zoom out even if stacking hasn't reached maximum stacks
if (offTrigger != null && offTrigger.check(triggerType, slot, entityWrapper)) {
return zoomOut(weaponStack, weaponTitle, entityWrapper, zoomData, slot);
}
// If trigger is valid zoom in or out depending on situation
if (trigger.check(triggerType, slot, entityWrapper)) {
int maximumStacks = config.getInt(weaponTitle + ".Scope.Zoom_Stacking.Maximum_Stacks");
if (maximumStacks <= 0) {
// Should turn off
return zoomOut(weaponStack, weaponTitle, entityWrapper, zoomData, slot);
}
if (zoomData.getZoomStacks() < maximumStacks) {
// Zoom in handles stacking on its own
return zoomIn(weaponStack, weaponTitle, entityWrapper, zoomData, slot);
}
// Should turn off (because zoom stacks have reached maximum stacks)
return zoomOut(weaponStack, weaponTitle, entityWrapper, zoomData, slot);
}
} else if (trigger.check(triggerType, slot, entityWrapper)) {
// Try zooming in since entity is not zooming
return zoomIn(weaponStack, weaponTitle, entityWrapper, zoomData, slot);
}
return false;
}
use of me.deecaad.weaponmechanics.wrappers.ZoomData in project MechanicsMain by WeaponMechanics.
the class OutAbilitiesListener method onPacket.
@Override
public void onPacket(Packet packet) {
EntityWrapper entityWrapper = WeaponMechanics.getEntityWrapper(packet.getPlayer());
ZoomData main = entityWrapper.getMainHandData().getZoomData();
ZoomData off = entityWrapper.getOffHandData().getZoomData();
// Not zooming
if (!main.isZooming() && !off.isZooming())
return;
int zoomAmount = main.isZooming() ? main.getZoomAmount() : off.getZoomAmount();
// Set the f field to scope level amount.
// f field means walk speed field
packet.setFieldValue(walkSpeedField, ScopeLevel.getScope(zoomAmount));
}
Aggregations