Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an accuracy field to bows. #4852

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,14 @@ public class ${name}Item extends Item {
if (player.getAbilities().instabuild || stack != ItemStack.EMPTY) {
<#assign projectileClass = generator.map(projectile, "projectiles", 0)>
<#if projectile.startsWith("CUSTOM:")>
${projectileClass} projectile = ${projectileClass}.shoot(world, entity, world.getRandom());
${projectileClass} projectile = ${projectileClass}.shoot(world, entity, world.getRandom(), ${data.rangedAccuracy});
<#elseif projectile.endsWith("Arrow")>
${projectileClass} projectile = new ${projectileClass}(world, entity);
projectile.shootFromRotation(entity, entity.getXRot(), entity.getYRot(), 0, 3.15f, 1.0F);
projectile.shootFromRotation(entity, entity.getXRot(), entity.getYRot(), 0, 3.15f, ${data.rangedAccuracy}F);
world.addFreshEntity(projectile);
world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), ForgeRegistries.SOUND_EVENTS
.getValue(new ResourceLocation("entity.arrow.shoot")), SoundSource.PLAYERS, 1, 1f / (world.getRandom().nextFloat() * 0.5f + 1));
</#if>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also unrelated. Applies to both MC versions. Please use https://github.com/MCreator/MCreator/pull/4852/files tab to find such changes.

Please fix all of them, not just the ones I mark

<#if data.damageCount != 0>
itemstack.hurtAndBreak(1, entity, e -> e.broadcastBreakEvent(entity.getUsedItemHand()));
</#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ public class ${name}Entity extends AbstractArrow implements ItemSupplier {
this.discard();
}

public static ${name}Entity shoot(Level world, LivingEntity entity, RandomSource source) {
return shoot(world, entity, source, ${data.power}f, ${data.damage}, ${data.knockback});
public static ${name}Entity shoot(Level world, LivingEntity entity, RandomSource source, double inaccuracy) {
return shoot(world, entity, source, ${data.power}f, ${data.damage}, ${data.knockback}, inaccuracy);
}

public static ${name}Entity shoot(Level world, LivingEntity entity, RandomSource random, float power, double damage, int knockback) {
public static ${name}Entity shoot(Level world, LivingEntity entity, RandomSource random, float power, double damage, int knockback, double inaccuracy) {
${name}Entity entityarrow = new ${name}Entity(${JavaModName}Entities.${data.getModElement().getRegistryNameUpper()}.get(), entity, world);
entityarrow.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y, entity.getViewVector(1).z, power * 2, 0);
entityarrow.shootFromRotation(entity, entity.getXRot(), entity.getYRot(), 0, power * 2, (float) inaccuracy);
entityarrow.setSilent(true);
entityarrow.setCritArrow(${data.showParticles});
entityarrow.setBaseDamage(damage);
Expand Down Expand Up @@ -182,7 +182,6 @@ public class ${name}Entity extends AbstractArrow implements ItemSupplier {

return entityarrow;
}

}
</#compress>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<#include "../triggers.java.ftl">

package ${package}.item;

import net.minecraft.world.entity.ai.attributes.Attributes;

<#compress>
Expand Down Expand Up @@ -305,10 +304,10 @@ public class ${name}Item extends Item {
if (player.getAbilities().instabuild || stack != ItemStack.EMPTY) {
<#assign projectileClass = generator.map(projectile, "projectiles", 0)>
<#if projectile.startsWith("CUSTOM:")>
${projectileClass} projectile = ${projectileClass}.shoot(world, entity, world.getRandom());
${projectileClass} projectile = ${projectileClass}.shoot(world, entity, world.getRandom(), ${data.rangedAccuracy});
<#elseif projectile.endsWith("Arrow")>
${projectileClass} projectile = new ${projectileClass}(world, entity, stack);
projectile.shootFromRotation(entity, entity.getXRot(), entity.getYRot(), 0, 3.15f, 1.0F);
projectile.shootFromRotation(entity, entity.getXRot(), entity.getYRot(), 0, 3.15f, ${data.rangedAccuracy}F);
world.addFreshEntity(projectile);
world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), BuiltInRegistries.SOUND_EVENT
.get(new ResourceLocation("entity.arrow.shoot")), SoundSource.PLAYERS, 1, 1f / (world.getRandom().nextFloat() * 0.5f + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ public class ${name}Entity extends AbstractArrow implements ItemSupplier {
this.discard();
}

public static ${name}Entity shoot(Level world, LivingEntity entity, RandomSource source) {
return shoot(world, entity, source, ${data.power}f, ${data.damage}, ${data.knockback});
public static ${name}Entity shoot(Level world, LivingEntity entity, RandomSource source, double inaccuracy) {
return shoot(world, entity, source, ${data.power}f, ${data.damage}, ${data.knockback}, inaccuracy);
}

public static ${name}Entity shoot(Level world, LivingEntity entity, RandomSource random, float power, double damage, int knockback) {
public static ${name}Entity shoot(Level world, LivingEntity entity, RandomSource random, float power, double damage, int knockback, double inaccuracy) {
${name}Entity entityarrow = new ${name}Entity(${JavaModName}Entities.${data.getModElement().getRegistryNameUpper()}.get(), entity, world);
entityarrow.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y, entity.getViewVector(1).z, power * 2, 0);
entityarrow.shootFromRotation(entity, entity.getXRot(), entity.getYRot(), 0, power * 2, (float) inaccuracy);
entityarrow.setSilent(true);
entityarrow.setCritArrow(${data.showParticles});
entityarrow.setBaseDamage(damage);
Expand Down Expand Up @@ -170,7 +170,6 @@ public class ${name}Entity extends AbstractArrow implements ItemSupplier {

return entityarrow;
}

KlemenDEV marked this conversation as resolved.
Show resolved Hide resolved
}
</#compress>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Sets the accuracy of the projectile shot.

KlemenDEV marked this conversation as resolved.
Show resolved Hide resolved
Vanilla values:

* 0 - No Effect
* 1 - Bow
* 6 - Dispenser
1 change: 1 addition & 0 deletions plugins/mcreator-localization/lang/texts.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2496,6 +2496,7 @@ elementgui.item.ranged_properties=Ranged item properties
elementgui.item.enable_ranged_item=Is this item ranged (shoots projectiles)?
elementgui.item.projectile=Projectile to shoot:
elementgui.item.shoot_constantly=Shoot constantly when active?
elementgui.item.ranged_accuracy=Projectile accuracy:
elementgui.item.event_on_use=When ranged item shoots projectile
elementgui.item.can_use_ranged=Can use ranged item
elementgui.item.error_needs_name=Food needs a name
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/mcreator/element/types/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
// Ranged properties
public boolean enableRanged;
public boolean shootConstantly;
public double rangedAccuracy;
public ProjectileEntry projectile;
public Procedure onRangedItemUsed;
public Procedure rangedUseCondition;
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/net/mcreator/ui/modgui/ItemGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class ItemGUI extends ModElementGUI<Item> {
private LogicProcedureSelector glowCondition;

private final JCheckBox enableRanged = L10N.checkbox("elementgui.common.enable");

private final JSpinner rangedAccuracy = new JSpinner(new SpinnerNumberModel(1, 0, 10, 0.1));
KlemenDEV marked this conversation as resolved.
Show resolved Hide resolved
private final JCheckBox shootConstantly = L10N.checkbox("elementgui.common.enable");

private ProcedureSelector onRangedItemUsed;
Expand Down Expand Up @@ -424,7 +424,7 @@ public ItemGUI(MCreator mcreator, ModElement modElement, boolean editingMode) {

updateRangedPanel();

JPanel rangedProperties = new JPanel(new GridLayout(3, 2, 2, 2));
JPanel rangedProperties = new JPanel(new GridLayout(4, 2, 2, 2));
rangedProperties.setOpaque(false);

rangedProperties.add(HelpUtils.wrapWithHelpButton(this.withEntry("item/enable_ranged_item"),
Expand All @@ -441,7 +441,10 @@ public ItemGUI(MCreator mcreator, ModElement modElement, boolean editingMode) {
L10N.label("elementgui.item.shoot_constantly")));
shootConstantly.setOpaque(false);
rangedProperties.add(shootConstantly);

rangedAccuracy.setOpaque(false);
rangedProperties.add(HelpUtils.wrapWithHelpButton(this.withEntry("item/rangedAccuracy"),
L10N.label("elementgui.item.ranged_accuracy")));
rangedProperties.add(rangedAccuracy);
JPanel rangedTriggers = new JPanel(new GridLayout(2, 1, 2, 2));
rangedTriggers.setOpaque(false);
rangedTriggers.add(rangedUseCondition);
Expand Down Expand Up @@ -498,6 +501,7 @@ private void updateFoodPanel() {
private void updateRangedPanel() {
if (enableRanged.isSelected()) {
shootConstantly.setEnabled(true);
rangedAccuracy.setEnabled(true);
projectile.setEnabled(true);
onRangedItemUsed.setEnabled(true);
rangedUseCondition.setEnabled(true);
Expand All @@ -511,6 +515,7 @@ private void updateRangedPanel() {
}
} else {
shootConstantly.setEnabled(false);
rangedAccuracy.setEnabled(false);
projectile.setEnabled(false);
onRangedItemUsed.setEnabled(false);
rangedUseCondition.setEnabled(false);
Expand Down Expand Up @@ -608,6 +613,7 @@ else if (page == 2)
eatResultItem.setBlock(item.eatResultItem);
enableRanged.setSelected(item.enableRanged);
shootConstantly.setSelected(item.shootConstantly);
rangedAccuracy.setValue(item.rangedAccuracy);
projectile.setSelectedItem(item.projectile);
rangedUseCondition.setSelectedProcedure(item.rangedUseCondition);
onRangedItemUsed.setSelectedProcedure(item.onRangedItemUsed);
Expand Down Expand Up @@ -665,6 +671,7 @@ else if (page == 2)
item.eatResultItem = eatResultItem.getBlock();
item.enableRanged = enableRanged.isSelected();
item.shootConstantly = shootConstantly.isSelected();
item.rangedAccuracy = (double) rangedAccuracy.getValue();
item.projectile = new ProjectileEntry(mcreator.getWorkspace(), projectile.getSelectedItem());
item.onRangedItemUsed = onRangedItemUsed.getSelectedProcedure();
item.rangedUseCondition = rangedUseCondition.getSelectedProcedure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ Color.white, new Procedure("condition4"),
item.projectile = new ProjectileEntry(modElement.getWorkspace(),
getRandomDataListEntry(random, ElementUtil.loadArrowProjectiles(modElement.getWorkspace())));
item.shootConstantly = emptyLists;
item.rangedAccuracy = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test value should differ from default value in UI

item.onRangedItemUsed = new Procedure("procedure4");
item.rangedUseCondition = new Procedure("condition1");
return item;
Expand Down
Loading