-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unsure - changed machine ranges into an attachment.
- Loading branch information
Showing
11 changed files
with
219 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/machines/java/com/enderio/machines/common/attachment/ActionRange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.enderio.machines.common.attachment; | ||
|
||
import com.enderio.api.UseOnly; | ||
import com.enderio.base.common.particle.RangeParticleData; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.core.BlockPos; | ||
import net.neoforged.fml.LogicalSide; | ||
|
||
public record ActionRange(int range, boolean isVisible) { | ||
public static final Codec<ActionRange> CODEC = RecordCodecBuilder.create(instance -> | ||
instance.group( | ||
Codec.INT.fieldOf("range").forGetter(ActionRange::range), | ||
Codec.BOOL.fieldOf("isVisible").forGetter(ActionRange::isVisible) | ||
).apply(instance, ActionRange::new)); | ||
|
||
public ActionRange visible() { | ||
return new ActionRange(range, true); | ||
} | ||
|
||
public ActionRange invisible() { | ||
return new ActionRange(range, false); | ||
} | ||
|
||
public ActionRange increment() { | ||
return new ActionRange(range + 1, isVisible); | ||
} | ||
|
||
public ActionRange decrement() { | ||
return new ActionRange(range - 1, isVisible); | ||
} | ||
|
||
@UseOnly(LogicalSide.CLIENT) | ||
public void addClientParticle(ClientLevel level, BlockPos pos, String color) { | ||
if (!isVisible) { | ||
return; | ||
} | ||
|
||
if (level.isClientSide()) { | ||
level.addAlwaysVisibleParticle(new RangeParticleData(range, color), true, pos.getX(), pos.getY(), pos.getZ(), 0, 0, 0); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/machines/java/com/enderio/machines/common/attachment/IRangedActor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.enderio.machines.common.attachment; | ||
|
||
public interface IRangedActor { | ||
|
||
int getMaxRange(); | ||
|
||
ActionRange getActionRange(); | ||
|
||
void setActionRange(ActionRange actionRange); | ||
|
||
default int getRange() { | ||
return getActionRange().range(); | ||
} | ||
|
||
default boolean isRangeVisible() { | ||
return getActionRange().isVisible(); | ||
} | ||
|
||
default void setRangeVisible(boolean isRangeVisible) { | ||
if (isRangeVisible) { | ||
setActionRange(getActionRange().visible()); | ||
} else { | ||
setActionRange(getActionRange().invisible()); | ||
} | ||
} | ||
|
||
default void increaseRange() { | ||
var actionRange = getActionRange(); | ||
if (actionRange.range() < getMaxRange()) { | ||
setActionRange(actionRange.increment()); | ||
} | ||
} | ||
|
||
default void decreaseRange() { | ||
var actionRange = getActionRange(); | ||
if (actionRange.range() > 0) { | ||
setActionRange(actionRange.decrement()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.