Skip to content

Commit

Permalink
Revert "Merge pull request #701 from chj990707/proximity-variable-angle"
Browse files Browse the repository at this point in the history
This reverts commit 88a99b9, reversing
changes made to 96cf3b9.
  • Loading branch information
rbasamoyai committed Dec 28, 2024
1 parent 88a99b9 commit 2e84414
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@
"createbigcannons.gui.autocannon_ammo_container.tracer_slot": "Tracer/Secondary Rounds",
"createbigcannons.gui.autocannon_ammo_container.tracer_spacing": "Tracer Spacing: Every %s round(s)",
"createbigcannons.gui.set_proximity_fuze.distance": "Detonation Distance: %s blocks",
"createbigcannons.gui.set_proximity_fuze.degrees": "Detonation Angle: %s degrees",
"createbigcannons.gui.set_timed_fuze.time": "Fuze Time: %ss %s ticks",
"createbigcannons.ponder.cannon_crafting/basin_foundry.header": "Using the Basin Foundry Lid",
"createbigcannons.ponder.cannon_crafting/basin_foundry.text_1": "Basin Foundry Lids are used to melt down metals for cannon casting.",
Expand Down Expand Up @@ -595,8 +594,8 @@
"item.createbigcannons.proximity_fuze.tooltip.behaviour2": "The fuze detonates after the projectile gets is within the set range of a block.",
"item.createbigcannons.proximity_fuze.tooltip.condition1": "When R-Clicked",
"item.createbigcannons.proximity_fuze.tooltip.condition2": "Detonation",
"item.createbigcannons.proximity_fuze.tooltip.shell_info": "Detonation Distance: _%s blocks_\nDetonation Angle: _%s degrees_",
"item.createbigcannons.proximity_fuze.tooltip.shell_info.item": "Detonation Distance: %s blocks\nDetonation Angle: %s degrees",
"item.createbigcannons.proximity_fuze.tooltip.shell_info": "Detonation Distance: _%s blocks_",
"item.createbigcannons.proximity_fuze.tooltip.shell_info.item": "Detonation Distance: %s blocks",
"item.createbigcannons.proximity_fuze.tooltip.summary": "Detonates when it _gets close_ to a block. This must be mounted on the _front_ of a shell; it will not work as a _base fuze._",
"item.createbigcannons.quickfiring_mechanism": "Quick-Firing Mechanism",
"item.createbigcannons.ram_rod": "Ram Rod",
Expand Down Expand Up @@ -711,4 +710,4 @@
"tooltip.createbigcannons.jei_info.added_fuze": "+ Fuze",
"tooltip.createbigcannons.jei_info.added_power": "+ Power",
"tooltip.createbigcannons.tracer": "+ Tracer"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@
"createbigcannons.gui.autocannon_ammo_container.tracer_slot": "Tracer/Secondary Rounds",
"createbigcannons.gui.autocannon_ammo_container.tracer_spacing": "Tracer Spacing: Every %s round(s)",
"createbigcannons.gui.set_proximity_fuze.distance": "Detonation Distance: %s blocks",
"createbigcannons.gui.set_proximity_fuze.degrees": "Detonation Angle: %s degrees",
"createbigcannons.gui.set_timed_fuze.time": "Fuze Time: %ss %s ticks",
"createbigcannons.ponder.cannon_crafting/basin_foundry.header": "Using the Basin Foundry Lid",
"createbigcannons.ponder.cannon_crafting/basin_foundry.text_1": "Basin Foundry Lids are used to melt down metals for cannon casting.",
Expand Down Expand Up @@ -595,8 +594,8 @@
"item.createbigcannons.proximity_fuze.tooltip.behaviour2": "The fuze detonates after the projectile gets is within the set range of a block.",
"item.createbigcannons.proximity_fuze.tooltip.condition1": "When R-Clicked",
"item.createbigcannons.proximity_fuze.tooltip.condition2": "Detonation",
"item.createbigcannons.proximity_fuze.tooltip.shell_info": "Detonation Distance: _%s blocks_\nDetonation Angle: _%s degrees_",
"item.createbigcannons.proximity_fuze.tooltip.shell_info.item": "Detonation Distance: %s blocks\nDetonation Angle: %s degrees",
"item.createbigcannons.proximity_fuze.tooltip.shell_info": "Detonation Distance: _%s blocks_",
"item.createbigcannons.proximity_fuze.tooltip.shell_info.item": "Detonation Distance: %s blocks",
"item.createbigcannons.proximity_fuze.tooltip.summary": "Detonates when it _gets close_ to a block. This must be mounted on the _front_ of a shell; it will not work as a _base fuze._",
"item.createbigcannons.quickfiring_mechanism": "Quick-Firing Mechanism",
"item.createbigcannons.ram_rod": "Ram Rod",
Expand Down Expand Up @@ -711,4 +710,4 @@
"tooltip.createbigcannons.jei_info.added_fuze": "+ Fuze",
"tooltip.createbigcannons.jei_info.added_power": "+ Power",
"tooltip.createbigcannons.tracer": "+ Tracer"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@

public class ItemStackServerData implements ContainerData {
private final ItemStack stack;
private final String[] tags;
private final String tag;

public ItemStackServerData(ItemStack stack, String... tags) {
public ItemStackServerData(ItemStack stack, String tag) {
this.stack = stack;
this.tags = tags;
this.tag = tag;
}

@Override
public int get(int index) {
return this.stack.getOrCreateTag().getInt(this.tags[index]);
return index == 0 ? this.stack.getOrCreateTag().getInt(this.tag) : 1;
}

@Override
public void set(int index, int value) {
this.stack.getOrCreateTag().putInt(this.tags[index], value);
if (index == 0) this.stack.getOrCreateTag().putInt(this.tag, value);
}

@Override
public int getCount() {
return tags.length;
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public static void prepare() {
REGISTRATE.addLang("death.attack", CreateBigCannons.resource("molten_metal"), "player", "%s burned in molten metal");
REGISTRATE.addRawLang(CreateBigCannons.MOD_ID + ".gui.set_timed_fuze.time", "Fuze Time: %ss %s ticks");
REGISTRATE.addRawLang(CreateBigCannons.MOD_ID + ".gui.set_proximity_fuze.distance", "Detonation Distance: %s blocks");
REGISTRATE.addRawLang(CreateBigCannons.MOD_ID + ".gui.set_proximity_fuze.degrees", "Detonation Angle: %s degrees");
REGISTRATE.addRawLang(CreateBigCannons.MOD_ID + ".gui.autocannon_ammo_container.tracer_spacing", "Tracer Spacing: Every %s round(s)");
REGISTRATE.addRawLang(CreateBigCannons.MOD_ID + ".gui.autocannon_ammo_container.tracer_slot", "Tracer/Secondary Rounds");

Expand Down Expand Up @@ -144,8 +143,8 @@ public static void prepare() {
.conditionAndBehavior("When R-Clicked", "Opens the _Set Proximity Fuze_ menu, where the detonation distance can be set.")
.conditionAndBehavior("Detonation", "The fuze detonates after the projectile gets is within the set range of a block.");

REGISTRATE.addLang("item", CBCItems.PROXIMITY_FUZE.getId(), "tooltip.shell_info", "Detonation Distance: _%s blocks_\nDetonation Angle: _%s degrees_");
REGISTRATE.addLang("item", CBCItems.PROXIMITY_FUZE.getId(), "tooltip.shell_info.item", "Detonation Distance: %s blocks\nDetonation Angle: %s degrees");
REGISTRATE.addLang("item", CBCItems.PROXIMITY_FUZE.getId(), "tooltip.shell_info", "Detonation Distance: _%s blocks_");
REGISTRATE.addLang("item", CBCItems.PROXIMITY_FUZE.getId(), "tooltip.shell_info.item", "Detonation Distance: %s blocks");

tooltip(CBCItems.CANNON_CRAFTING_WAND)
.header("CANNON CRAFTING WAND")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum CBCGuiTextures implements ScreenElement {
TIMED_FUZE_SELECTOR("backgrounds1", 179, 0, 7, 26),

PROXIMITY_FUZE_BG("backgrounds1", 0, 84, 179, 83),
PROXIMITY_FUZE_SELECTOR("backgrounds1", 179, 84, 9, 20),
PROXIMITY_FUZE_SELECTOR("backgrounds1", 179, 84, 9, 26),

AUTOCANNON_AMMO_CONTAINER_BG("backgrounds1", 0, 168, 179, 83),
AUTOCANNON_AMMO_CONTAINER_SELECTOR("backgrounds1", 179, 168, 9, 14),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@
public class ProximityFuzeContainer extends AbstractFuzeContainer {

public static ProximityFuzeContainer getServerMenu(int id, Inventory playerInv, ItemStack stack) {
return new ProximityFuzeContainer(CBCMenuTypes.SET_PROXIMITY_FUZE.get(), id, new ItemStackServerData(stack, "DetonationDistance", "DetonationAngle"), ItemStack.EMPTY);
return new ProximityFuzeContainer(CBCMenuTypes.SET_PROXIMITY_FUZE.get(), id, new ItemStackServerData(stack, "DetonationDistance"), ItemStack.EMPTY);
}

public static ProximityFuzeContainer getClientMenu(MenuType<ProximityFuzeContainer> type, int id, Inventory playerInv, FriendlyByteBuf buf) {
ContainerData data = new SimpleContainerData(2);
ContainerData data = new SimpleContainerData(1);
data.set(0, buf.readVarInt());
data.set(1, buf.readVarInt());
return new ProximityFuzeContainer(type, id, data, buf.readItem());
}

protected ProximityFuzeContainer(MenuType<? extends ProximityFuzeContainer> type, int windowId, ContainerData data, ItemStack stackToRender) {
super(type, windowId, data, stackToRender);
}

public void setAngleValue(int angle) { this.data.set(1, angle); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;

import org.joml.AxisAngle4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;

import rbasamoyai.createbigcannons.CreateBigCannons;
import rbasamoyai.createbigcannons.config.CBCConfigs;
import rbasamoyai.createbigcannons.index.CBCItems;
Expand Down Expand Up @@ -71,73 +66,33 @@ public boolean onProjectileClip(ItemStack stack, AbstractCannonProjectile projec
if (!tag.contains("Armed")) return false;

double l = Math.max(tag.getInt("DetonationDistance"), 1);
double angle = Math.toRadians(Math.max(tag.getInt("DetonationAngle"),0));
Vec3 dir = projectile.getDeltaMovement().normalize();
Vector3f dirNorm3f = dir.toVector3f();
Vec3 right = dir.cross(new Vec3(Direction.UP.step()));
Vec3 up = dir.cross(right);
dir = dir.scale(l);

Vec3 trajectory = end.subtract(start);
Vec3 normalizedTraj = trajectory.normalize();

Vector3f dir3f = dir.toVector3f();
Vector3f right3f = right.toVector3f();
Quaternionf rotationAxial = new Quaternionf(new AxisAngle4f((float)Math.toRadians(30), dirNorm3f));
Quaternionf rotationRadial = new Quaternionf(new AxisAngle4f((float)angle, right3f));
Quaternionf rotationRadialThird = new Quaternionf(new AxisAngle4f((float)angle/3, right3f));
Vec3 rayStart = new Vec3(start.x, start.y, start.z);
for (int i = 0; i < trajectory.length() / 2;i++){
Vector3f dirRotated = new Vector3f(dir3f);
dirRotated.rotate(rotationRadial);
for (int j = 0; j < 12; j++){
Vec3 rayEnd = new Vec3(dirRotated).add(rayStart);
if (projectile.level().clip(new ClipContext(rayStart, rayEnd, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, projectile)).getType() != HitResult.Type.MISS) {
return true;
}
dirRotated.rotate(rotationAxial);
}
rayStart = rayStart.add(dir.normalize().scale(i * 2));
}
rayStart = new Vec3(end.x, end.y, end.z);
for (int i = 0; i < 3;i++){
Vector3f dirRotated = new Vector3f(dir3f);
dirRotated.rotate(rotationRadialThird);
for(int i2 = 0; i2 < i; i2++){
dirRotated.rotate(rotationRadialThird);
}
for (int j = 0; j < 12; j++){
Vec3 rayEnd = new Vec3(dirRotated).add(rayStart);
if (projectile.level().clip(new ClipContext(rayStart, rayEnd, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, projectile)).getType() != HitResult.Type.MISS) {
return true;
}
dirRotated.rotate(rotationAxial);
}
}
if (projectile.level().clip(new ClipContext(end, end.add(dir), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, projectile)).getType() != HitResult.Type.MISS) {
return true;
}
double reach = Math.max(projectile.getBbWidth(), projectile.getBbHeight()) * 0.5;

AABB currentMovementRegion = projectile.getBoundingBox()
.expandTowards(dir.scale(1.75))
.inflate(l)
.inflate(1)
.move(start.subtract(projectile.position()));
List<Entity> entities = projectile.level().getEntities(projectile, currentMovementRegion, projectile::canHitEntity);

for (Entity target : entities) {
float targetRadius = Math.max(target.getBbHeight(), target.getBbWidth())/2;
Vec3 relPos = target.position().subtract(start);
double frontalDist = normalizedTraj.dot(relPos);
double lateralDist = normalizedTraj.cross(relPos).length();
if (lateralDist > (l + targetRadius) * Math.sin(angle)) continue;
double minimalDist = -targetRadius;
double maximalDist = trajectory.length() + l + targetRadius;
if (angle > 0){
minimalDist = lateralDist * 1 / Math.tan(angle) - targetRadius;
maximalDist = trajectory.length() + Math.sqrt((l + targetRadius) * (l + targetRadius) - lateralDist * lateralDist);
}
if (frontalDist >= minimalDist && frontalDist <= maximalDist){
return true;
int radius = 2;
double scale = 1.5;
for (int i = -radius; i <= radius; ++i) {
for (int j = -radius; j <= radius; ++j) {
Vec3 ray = dir.add(right.scale(i * scale)).add(up.scale(j * scale));
Vec3 rayEnd = start.add(ray);

if (projectile.level().clip(new ClipContext(start, rayEnd, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, projectile)).getType() != HitResult.Type.MISS) {
return true;
}

for (Entity target : entities) {
AABB targetBox = target.getBoundingBox().inflate(reach);
if (targetBox.clip(start, rayEnd).isPresent()) return true;
}
}
}

Expand All @@ -152,14 +107,9 @@ public InteractionResultHolder<ItemStack> use(Level level, Player player, Intera
if (!tag.contains("DetonationDistance")) {
tag.putInt("DetonationDistance", 1);
}
if (!tag.contains("DetonationAngle")){
tag.putInt("DetonationAngle",0);
}
int dist = tag.getInt("DetonationDistance");
int ang = tag.getInt("DetonationAngle");
CBCMenuTypes.SET_PROXIMITY_FUZE.open(splayer, this.getDisplayName(), this, buf -> {
buf.writeVarInt(dist);
buf.writeVarInt(ang);
buf.writeItem(new ItemStack(this));
});
}
Expand All @@ -179,15 +129,14 @@ public Component getDisplayName() {
public static ItemStack getCreativeTabItem(int defaultFuze) {
ItemStack stack = CBCItems.PROXIMITY_FUZE.asStack();
stack.getOrCreateTag().putInt("DetonationDistance", 1);
stack.getOrCreateTag().putInt("DetonationAngle",0);
return stack;
}

@Override
public void addExtraInfo(List<Component> tooltip, boolean isSneaking, ItemStack stack) {
super.addExtraInfo(tooltip, isSneaking, stack);
MutableComponent info = Lang.builder("item")
.translate(CreateBigCannons.MOD_ID + ".proximity_fuze.tooltip.shell_info", stack.getOrCreateTag().getInt("DetonationDistance"), stack.getOrCreateTag().getInt("DetonationAngle"))
.translate(CreateBigCannons.MOD_ID + ".proximity_fuze.tooltip.shell_info", stack.getOrCreateTag().getInt("DetonationDistance"))
.component();
tooltip.addAll(TooltipHelper.cutTextComponent(info, Style.EMPTY, Style.EMPTY, 6));
}
Expand All @@ -196,7 +145,7 @@ public void addExtraInfo(List<Component> tooltip, boolean isSneaking, ItemStack
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flag) {
super.appendHoverText(stack, level, tooltip, flag);
tooltip.add(Lang.builder("item")
.translate(CreateBigCannons.MOD_ID + ".proximity_fuze.tooltip.shell_info.item", stack.getOrCreateTag().getInt("DetonationDistance"), stack.getOrCreateTag().getInt("DetonationAngle"))
.translate(CreateBigCannons.MOD_ID + ".proximity_fuze.tooltip.shell_info.item", stack.getOrCreateTag().getInt("DetonationDistance"))
.component());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,16 @@
import net.minecraft.world.entity.player.Inventory;
import rbasamoyai.createbigcannons.CreateBigCannons;
import rbasamoyai.createbigcannons.index.CBCGuiTextures;
import rbasamoyai.createbigcannons.multiloader.NetworkPlatform;
import rbasamoyai.createbigcannons.network.ServerBoundSetProximityAnglePacket;

public class ProximityFuzeScreen extends AbstractFuzeScreen<ProximityFuzeContainer> {

protected ScrollInput AngleScroll;

public ProximityFuzeScreen(ProximityFuzeContainer menu, Inventory playerInv, Component title) {
super(menu, playerInv, title);
}

@Override
protected void init() {
super.init();
AngleScroll = new ScrollInput(this.leftPos + 36, this.topPos + 39, 102, 12)
.withRange(0, 91)
.calling(state -> {
this.lastUpdated = 0;
AngleScroll.titled(Lang.builder(CreateBigCannons.MOD_ID).translate("gui.set_proximity_fuze.degrees", state).component());
})
.setState(Mth.clamp(this.menu.data.get(1), 0, 91));
AngleScroll.onChanged();
this.addRenderableWidget(AngleScroll);
}

@Override
protected void containerTick() {
super.containerTick();

if (this.lastUpdated >= 0) {
this.lastUpdated++;
}
if (this.lastUpdated >= 20) {
this.updateServerAngle();
this.lastUpdated = -1;
}
}

@Override
public void removed() {
super.removed();
this.updateServerAngle();
}

@Override
public void onClose() {
this.updateServerAngle();
super.onClose();
}

private void updateServerAngle() {
NetworkPlatform.sendToServer(new ServerBoundSetProximityAnglePacket(this.AngleScroll.getState()));
}

@Override
protected ScrollInput getScrollInput() {
return new ScrollInput(this.leftPos + 36, this.topPos + 21, 102, 12)
return new ScrollInput(this.leftPos + 36, this.topPos + 29, 102, 18)
.withRange(1, 33)
.calling(state -> {
this.lastUpdated = 0;
Expand All @@ -88,13 +41,7 @@ protected void renderBg(GuiGraphics graphics, float partialTicks, int mouseX, in
double s = 100.0d / (double)(top - 1);
int offsX = this.setValue.getState();
offsX = offsX == top ? 100 : (int) Math.ceil((double) offsX * s - s);
CBCGuiTextures.PROXIMITY_FUZE_SELECTOR.render(graphics, this.leftPos + 32 + offsX, this.topPos + 13);

int top2 = 90;
double s2 = 100.0d / (double)(top2);
int offsX2 = AngleScroll.getState();
offsX2 = offsX2 == top2? 100 : (int) Math.ceil((double) offsX2 * s2 - s2);
CBCGuiTextures.PROXIMITY_FUZE_SELECTOR.render(graphics, this.leftPos + 32 + offsX2, this.topPos + 31);
CBCGuiTextures.PROXIMITY_FUZE_SELECTOR.render(graphics, this.leftPos + 32 + offsX, this.topPos + 21);

GuiGameElement.of(this.menu.getStackToRender())
.<GuiGameElement.GuiItemRenderBuilder>at(this.leftPos + 185, this.topPos + 26, -200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static void init() {
addMsg(id++, ServerboundFiringActionPacket.class, ServerboundFiringActionPacket::new);
addMsg(id++, ServerboundSetFireRatePacket.class, ServerboundSetFireRatePacket::new);
addMsg(id++, ServerboundSetContainerValuePacket.class, ServerboundSetContainerValuePacket::new);
addMsg(id++, ServerBoundSetProximityAnglePacket.class, ServerBoundSetProximityAnglePacket::new);
addMsg(id++, ClientboundMunitionPropertiesPacket.class, ClientboundMunitionPropertiesPacket::copyOf);
addMsg(id++, ClientboundAutocannonMaterialPropertiesPacket.class, ClientboundAutocannonMaterialPropertiesPacket::copyOf);
addMsg(id++, ClientboundBigCannonMaterialPropertiesPacket.class, ClientboundBigCannonMaterialPropertiesPacket::copyOf);
Expand Down
Loading

0 comments on commit 2e84414

Please sign in to comment.