This commit is contained in:
Chipperfluff 2025-12-19 12:13:43 +01:00
parent 8b2ebafe56
commit fcee5d7ee8
26 changed files with 571 additions and 362 deletions

327
agents.md Normal file
View File

@ -0,0 +1,327 @@
# Coding Guidelines (Java written C/C++-style)
These rules exist to **preserve intent, structure, and mental parseability**.
Formatting must reflect **logic**, not arbitrary line limits or formatter preferences.
Java syntax, **C/C++ brain**.
---
## 1. General Philosophy
* Java is written **as if it were C/C++**
* Formatting must never change perceived control flow
* Readability = how fast the code parses *correctly* in your head
* Tools must adapt to the codebase, not the other way around
---
## 2. Indentation & Whitespace
* **Indentation: 4 spaces**
* **No tabs**
* Avoid excessive vertical whitespace
* Blank lines only where they add logical separation
✅ **Good**
```java
int sum(int a, int b) {
int r = a + b;
return r;
}
```
❌ **Bad**
```java
int sum(int a, int b)
{
int r = a + b;
return r;
}
```
---
## 3. Braces
* Braces are **always required**
* Opening brace stays **on the same line**
* Never rely on implicit scopes
✅ **Good**
```java
if (value == null) {
return;
}
```
❌ **Bad**
```java
if (value == null)
{
return;
}
```
> Rationale: new-line braces create **false scope perception** and visual ambiguity.
---
## 4. Imports (IMPORTANT)
### ❗ Never use fully-qualified class names inline
❌ **Forbidden**
```java
net.minecraft.util.math.BlockPos pos = new net.minecraft.util.math.BlockPos(0, 0, 0);
```
✅ **Required**
```java
import net.minecraft.util.math.BlockPos;
BlockPos pos = new BlockPos(0, 0, 0);
```
### Why:
* Fully-qualified names **destroy readability**
* They bloat expressions and hide logic
* Imports exist to solve exactly this problem
**Rule:**
> If you need a class, **import it**.
> If imports collide, resolve the collision explicitly — do *not* inline paths everywhere.
---
## 5. Function & Method Definitions
* **Method signatures must stay on one line**
* Never break parameters across multiple lines
* Length is acceptable; ambiguity is not
✅ **Good**
```java
void processUser(User user, int flags, boolean force, long timeout) {
...
}
```
❌ **Bad**
```java
void processUser(
User user,
int flags,
boolean force,
long timeout
) {
...
}
```
> Reason: multiline signatures look like scopes and break C/C++ mental parsing.
---
## 6. Function Calls & Argument Layout
### Default rule
* **Single-line calls are preferred**
* Flat calls stay flat
* Length alone is **not** a reason to wrap
✅ **Good**
```java
Color color = user.getProfile().getSettings().getTheme().getPrimaryColor();
```
---
### When multiline calls ARE allowed (and expected)
Multiline calls are allowed **only when**:
* The call is **structural / declarative**
* Each argument is conceptually distinct
* Nesting would otherwise hide meaning
### Example (correct usage)
```java
BiomeModifications.addFeature(
BiomeSelectors.foundInOverworld(),
GenerationStep.Feature.UNDERGROUND_ORES,
RegistryKey.of(
RegistryKeys.PLACED_FEATURE,
new Identifier("chipi", "chipper_ore")
)
);
```
### Why this is correct:
* Each argument represents a **different conceptual layer**
* Nested calls are grouped logically
* Visual structure mirrors logical structure
* This reads like a configuration block, not a simple call
---
### ❌ Incorrect multiline usage
```java
doThing(
a,
b,
c
);
```
> This adds vertical noise with **no semantic gain**.
---
## 7. Chained Calls
* Flat chains stay on one line
* Long or builder-style chains may be split vertically
* Each chained step gets its own line
✅ **Good**
```java
builder
.withColor(theme.getPrimaryColor())
.withSize(32)
.enableShadow()
.build();
```
❌ **Bad**
```java
builder.withColor(
theme.getPrimaryColor()
).withSize(
32
).enableShadow().build();
```
---
## 8. Control Flow & Returns
* **Early returns are encouraged**
* Avoid artificial nesting
* Single-exit functions are **not required**
✅ **Good**
```java
void handle(User user) {
if (user == null) return;
if (!user.isActive()) return;
process(user);
}
```
❌ **Bad**
```java
void handle(User user) {
if (user != null) {
if (user.isActive()) {
process(user);
}
}
}
```
---
## 9. One-Liners
* One-liners allowed for **simple guard clauses**
* No complex logic on one line
✅ **Allowed**
```java
if (value == null) return;
```
❌ **Not allowed**
```java
if (a == b && c != d && flag && check()) doThing();
```
---
## 10. Null Handling
* `null` is a **valid, intentional state**
* Do not over-engineer around it
* Prefer clarity over defensive clutter
✅ **Good**
```java
User user = findUser(id);
if (user == null) return;
```
---
## 11. Logging & Debug Output
* Logging must be **short and readable**
* Prefer `System.out.println` for quick diagnostics
* Verbose logging only when justified
✅ **Good**
```java
System.out.println("Loaded structure: " + id);
```
---
## 12. Autoformatters & Linters
Autoformatters **must not**:
* Break method signatures
* Move braces to new lines
* Introduce unwanted trailing newlines
* Rewrap stable code repeatedly
If a formatter fights these rules: **disable or reconfigure it**.
---
## Summary (Non-Negotiable)
* Java written with **C/C++ structure**
* Compact signatures, explicit layout
* Imports always used
* Multiline only when it adds meaning
* Formatting reflects logic, not fashion
> If a tool disagrees with this file, the tool is wrong.

View File

@ -37,14 +37,9 @@ public class ChipiMod implements ModInitializer {
public static final String MOD_ID = "chipi"; public static final String MOD_ID = "chipi";
public static final RegistryKey<World> CHIPI_DIMENSION_KEY = public static final RegistryKey<World> CHIPI_DIMENSION_KEY = RegistryKey.of(RegistryKeys.WORLD, new Identifier("chipi", "chipi_dimension"));
RegistryKey.of(
RegistryKeys.WORLD,
new Identifier("chipi", "chipi_dimension")
);
private static final Identifier SPAWN_STRUCTURE = private static final Identifier SPAWN_STRUCTURE = new Identifier("chipi", "spawn");
new Identifier("chipi", "spawn");
private static MinecraftServer SERVER; private static MinecraftServer SERVER;
@ -60,25 +55,17 @@ public class ChipiMod implements ModInitializer {
ChipiBlessingEvents.register(); ChipiBlessingEvents.register();
ChipiHungerHandler.register(); ChipiHungerHandler.register();
FabricDefaultAttributeRegistry.register( FabricDefaultAttributeRegistry.register(ModEntities.MEP, MepEntity.createMepAttributes());
ModEntities.MEP,
MepEntity.createMepAttributes()
);
BiomeModifications.addFeature( BiomeModifications.addFeature(
BiomeSelectors.foundInOverworld(), BiomeSelectors.foundInOverworld(),
GenerationStep.Feature.UNDERGROUND_ORES, GenerationStep.Feature.UNDERGROUND_ORES,
RegistryKey.of( RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier("chipi", "chipper_ore"))
RegistryKeys.PLACED_FEATURE,
new Identifier("chipi", "chipper_ore")
)
); );
CommandRegistrationCallback.EVENT.register( CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
(dispatcher, registryAccess, environment) -> { ChpCommand.register(dispatcher);
ChpCommand.register(dispatcher); });
}
);
ServerLifecycleEvents.SERVER_STARTED.register(server -> { ServerLifecycleEvents.SERVER_STARTED.register(server -> {
SERVER = server; SERVER = server;
@ -108,21 +95,17 @@ public class ChipiMod implements ModInitializer {
.get(GameRules.DO_DAYLIGHT_CYCLE) .get(GameRules.DO_DAYLIGHT_CYCLE)
.set(false, server); .set(false, server);
SpawnPlacedState state = SpawnPlacedState state = world.getPersistentStateManager().getOrCreate(
world.getPersistentStateManager().getOrCreate( SpawnPlacedState::fromNbt,
SpawnPlacedState::fromNbt, SpawnPlacedState::new,
SpawnPlacedState::new, "chipi_spawn"
"chipi_spawn" );
);
if (state.placed) { if (state.placed) {
return; return;
} }
StructureTemplate spawnTemplate = StructureTemplate spawnTemplate = world.getStructureTemplateManager().getTemplate(SPAWN_STRUCTURE).orElse(null);
world.getStructureTemplateManager()
.getTemplate(SPAWN_STRUCTURE)
.orElse(null);
if (spawnTemplate == null) { if (spawnTemplate == null) {
System.err.println("[CHIPI] spawn.nbt not found!"); System.err.println("[CHIPI] spawn.nbt not found!");
@ -131,14 +114,7 @@ public class ChipiMod implements ModInitializer {
BlockPos spawnCenter = new BlockPos(0, 80, 0); BlockPos spawnCenter = new BlockPos(0, 80, 0);
spawnTemplate.place( spawnTemplate.place(world, spawnCenter, spawnCenter, new StructurePlacementData(), world.getRandom(), 2);
world,
spawnCenter,
spawnCenter,
new StructurePlacementData(),
world.getRandom(),
2
);
world.setSpawnPos(spawnCenter.up(), 0.0f); world.setSpawnPos(spawnCenter.up(), 0.0f);

View File

@ -4,17 +4,13 @@ import net.minecraft.advancement.criterion.Criteria;
public class ModCriteria { public class ModCriteria {
public static final PortalActivatedTrigger PORTAL_ACTIVATED = public static final PortalActivatedTrigger PORTAL_ACTIVATED = Criteria.register(new PortalActivatedTrigger());
Criteria.register(new PortalActivatedTrigger());
public static final PortalDestroyedTrigger PORTAL_DESTROYED = public static final PortalDestroyedTrigger PORTAL_DESTROYED = Criteria.register(new PortalDestroyedTrigger());
Criteria.register(new PortalDestroyedTrigger());
public static final VoidConsumedTrigger VOID_CONSUMED_TRIGGER = public static final VoidConsumedTrigger VOID_CONSUMED_TRIGGER = Criteria.register(new VoidConsumedTrigger());
Criteria.register(new VoidConsumedTrigger());
public static final VoidConsumedFireTrigger VOID_CONSUMED_FIRE_TRIGGER = public static final VoidConsumedFireTrigger VOID_CONSUMED_FIRE_TRIGGER = Criteria.register(new VoidConsumedFireTrigger());
Criteria.register(new VoidConsumedFireTrigger());
public static void register() { public static void register() {
// classload trigger // classload trigger

View File

@ -1,7 +1,6 @@
package net.Chipperfluff.chipi.advancement; package net.Chipperfluff.chipi.advancement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.advancement.criterion.AbstractCriterion; import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions; import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer; import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;

View File

@ -1,7 +1,6 @@
package net.Chipperfluff.chipi.advancement; package net.Chipperfluff.chipi.advancement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.advancement.criterion.AbstractCriterion; import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions; import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer; import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;

View File

@ -1,7 +1,6 @@
package net.Chipperfluff.chipi.advancement; package net.Chipperfluff.chipi.advancement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.advancement.criterion.AbstractCriterion; import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions; import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer; import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;

View File

@ -1,7 +1,6 @@
package net.Chipperfluff.chipi.advancement; package net.Chipperfluff.chipi.advancement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.advancement.criterion.AbstractCriterion; import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions; import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer; import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;

View File

@ -16,16 +16,14 @@ public class ChipperFrameBlock extends PillarBlock {
} }
@Override @Override
public void onPlaced( public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
if (!world.isClient) { if (!world.isClient) {
ChipperPortalShape.tryCreate(world, pos); ChipperPortalShape.tryCreate(world, pos);
} }
} }
@Override @Override
public void onStateReplaced( public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (!world.isClient && state.getBlock() != newState.getBlock()) { if (!world.isClient && state.getBlock() != newState.getBlock()) {
ChipperPortalShape.destroyNearby(world, pos); ChipperPortalShape.destroyNearby(world, pos);

View File

@ -29,8 +29,7 @@ public class ChipperPortalBlock extends Block {
// Walk-through portal // Walk-through portal
@Override @Override
public VoxelShape getCollisionShape( public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return VoxelShapes.empty(); return VoxelShapes.empty();
} }
@ -46,8 +45,7 @@ public class ChipperPortalBlock extends Block {
} }
@Override @Override
public float calcBlockBreakingDelta( public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
return player.isCreative() ? super.calcBlockBreakingDelta(state, player, world, pos) : 0.0F; return player.isCreative() ? super.calcBlockBreakingDelta(state, player, world, pos) : 0.0F;
} }

View File

@ -2,6 +2,7 @@ package net.Chipperfluff.chipi.block;
import net.Chipperfluff.chipi.advancement.ModCriteria; import net.Chipperfluff.chipi.advancement.ModCriteria;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
@ -27,9 +28,8 @@ public class ChipperPortalShape {
if (shape.isValid()) { if (shape.isValid()) {
shape.placePortal(); shape.placePortal();
if (serverWorld.getClosestPlayer( if (serverWorld.getClosestPlayer(placedPos.getX(), placedPos.getY(), placedPos.getZ(), 10, false)
placedPos.getX(), placedPos.getY(), placedPos.getZ(), 10, false) instanceof ServerPlayerEntity serverPlayer) {
instanceof net.minecraft.server.network.ServerPlayerEntity serverPlayer) {
ModCriteria.PORTAL_ACTIVATED.trigger(serverPlayer); ModCriteria.PORTAL_ACTIVATED.trigger(serverPlayer);
} }
@ -46,7 +46,6 @@ public class ChipperPortalShape {
for (int x = 0; x < 4; x++) { for (int x = 0; x < 4; x++) {
for (int y = 0; y < 5; y++) { for (int y = 0; y < 5; y++) {
boolean edge = x == 0 || x == 3 || y == 0 || y == 4; boolean edge = x == 0 || x == 3 || y == 0 || y == 4;
BlockPos pos = offset(base, x, y); BlockPos pos = offset(base, x, y);
BlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
@ -83,8 +82,7 @@ public class ChipperPortalShape {
for (int x = 1; x <= 2; x++) { for (int x = 1; x <= 2; x++) {
for (int y = 1; y <= 3; y++) { for (int y = 1; y <= 3; y++) {
world.setBlockState( world.setBlockState(offset(base, x, y), ModBlocks.CHIPPER_PORTAL.getDefaultState(), 3);
offset(base, x, y), ModBlocks.CHIPPER_PORTAL.getDefaultState(), 3);
} }
} }
} }

View File

@ -13,45 +13,44 @@ import net.minecraft.util.Identifier;
public class ModBlocks { public class ModBlocks {
public static final Block VOID_BLOCK = public static final Block VOID_BLOCK = Registry.register(
Registry.register( Registries.BLOCK,
Registries.BLOCK, new Identifier(ChipiMod.MOD_ID, "void_block"),
new Identifier(ChipiMod.MOD_ID, "void_block"), new VoidBlock(
new VoidBlock( AbstractBlock.Settings.create()
AbstractBlock.Settings.create() .strength(-1.0F, 3600000.0F)
.strength(-1.0F, 3600000.0F) .mapColor(MapColor.BLACK)
.mapColor(MapColor.BLACK) .dropsNothing()
.dropsNothing() .pistonBehavior(PistonBehavior.BLOCK))
.pistonBehavior(PistonBehavior.BLOCK))); );
public static final Block CHIPPER_FRAME = public static final Block CHIPPER_FRAME = Registry.register(
Registry.register( Registries.BLOCK,
Registries.BLOCK, new Identifier(ChipiMod.MOD_ID, "chipper_frame"),
new Identifier(ChipiMod.MOD_ID, "chipper_frame"), new ChipperFrameBlock(FabricBlockSettings.create().strength(3.0f).requiresTool())
new ChipperFrameBlock( );
FabricBlockSettings.create().strength(3.0f).requiresTool()));
public static final Block CHIPPER_PORTAL = public static final Block CHIPPER_PORTAL = Registry.register(
Registry.register( Registries.BLOCK,
Registries.BLOCK, new Identifier(ChipiMod.MOD_ID, "chipper_portal"),
new Identifier(ChipiMod.MOD_ID, "chipper_portal"), new ChipperPortalBlock(
new ChipperPortalBlock( FabricBlockSettings.create()
FabricBlockSettings.create() .noCollision()
.noCollision() .luminance(3)
.luminance(3) .strength(-1.0f))
.strength(-1.0f))); );
public static final Block CHIPPER_ORE = public static final Block CHIPPER_ORE = Registry.register(
Registry.register( Registries.BLOCK,
Registries.BLOCK, new Identifier(ChipiMod.MOD_ID, "chipper_ore"),
new Identifier(ChipiMod.MOD_ID, "chipper_ore"), new Block(AbstractBlock.Settings.copy(Blocks.IRON_ORE).requiresTool())
new Block(AbstractBlock.Settings.copy(Blocks.IRON_ORE).requiresTool())); );
public static final Block CHIPPER_ALLOY_BLOCK = public static final Block CHIPPER_ALLOY_BLOCK = Registry.register(
Registry.register( Registries.BLOCK,
Registries.BLOCK, new Identifier(ChipiMod.MOD_ID, "chipper_alloy_block"),
new Identifier(ChipiMod.MOD_ID, "chipper_alloy_block"), new Block(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).requiresTool())
new Block(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).requiresTool())); );
public static void register() {} public static void register() {}
} }

View File

@ -32,7 +32,6 @@ public class VoidBlock extends Block {
} }
if (entity instanceof LivingEntity living) { if (entity instanceof LivingEntity living) {
if (living instanceof PlayerEntity player) { if (living instanceof PlayerEntity player) {
if (player.isCreative() || player.isSpectator()) { if (player.isCreative() || player.isSpectator()) {
return; return;
@ -41,15 +40,11 @@ public class VoidBlock extends Block {
boolean burning = living.isOnFire(); boolean burning = living.isOnFire();
Identifier damageId = Identifier damageId = burning ? new Identifier("chipi", "void_block_fire") : new Identifier("chipi", "void_block");
burning
? new Identifier("chipi", "void_block_fire")
: new Identifier("chipi", "void_block");
RegistryEntry<DamageType> damageType = RegistryEntry<DamageType> damageType = world.getRegistryManager()
world.getRegistryManager() .get(RegistryKeys.DAMAGE_TYPE)
.get(RegistryKeys.DAMAGE_TYPE) .entryOf(RegistryKey.of(RegistryKeys.DAMAGE_TYPE, damageId));
.entryOf(RegistryKey.of(RegistryKeys.DAMAGE_TYPE, damageId));
DamageSource source = new DamageSource(damageType); DamageSource source = new DamageSource(damageType);

View File

@ -10,10 +10,7 @@ public class ChipiClient implements ClientModInitializer {
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.CHIPPER_PORTAL, RenderLayer.getTranslucent());
BlockRenderLayerMap.INSTANCE.putBlock(
ModBlocks.CHIPPER_PORTAL, RenderLayer.getTranslucent());
ModEntityRenderers.register(); ModEntityRenderers.register();
} }
} }

View File

@ -10,8 +10,7 @@ import net.minecraft.util.Identifier;
public class MepRenderer extends BipedEntityRenderer<MepEntity, BipedEntityModel<MepEntity>> { public class MepRenderer extends BipedEntityRenderer<MepEntity, BipedEntityModel<MepEntity>> {
private static final Identifier TEXTURE = private static final Identifier TEXTURE = new Identifier(ChipiMod.MOD_ID, "textures/entity/mep.png");
new Identifier(ChipiMod.MOD_ID, "textures/entity/mep.png");
public MepRenderer(EntityRendererFactory.Context ctx) { public MepRenderer(EntityRendererFactory.Context ctx) {
super(ctx, new BipedEntityModel<>(ctx.getPart(EntityModelLayers.PLAYER)), 0.5f); super(ctx, new BipedEntityModel<>(ctx.getPart(EntityModelLayers.PLAYER)), 0.5f);

View File

@ -17,37 +17,29 @@ import net.minecraft.util.math.BlockPos;
public class ChpCommand { public class ChpCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register( dispatcher.register(
CommandManager.literal("chp") CommandManager.literal("chp")
.then( .then(
CommandManager.argument("name", StringArgumentType.word()) CommandManager.argument("name", StringArgumentType.word())
// autocomplete structure names // autocomplete structure names
.suggests( .suggests(
(ctx, builder) -> (ctx, builder) ->
CommandSource.suggestMatching( CommandSource.suggestMatching(ChipiStructures.getNames(), builder))
ChipiStructures.getNames(), .then(
builder)) CommandManager.argument("pos", BlockPosArgumentType.blockPos())
.then( // default: no marker
CommandManager.argument( .executes(ctx -> execute(ctx, false))
"pos", // optional marker flag
BlockPosArgumentType.blockPos()) .then(
// default: no marker CommandManager.argument("marker", BoolArgumentType.bool())
.executes(ctx -> execute(ctx, false)) .executes(
// optional marker flag ctx -> execute(ctx, BoolArgumentType.getBool(ctx, "marker")
.then( )
CommandManager.argument( )
"marker", )
BoolArgumentType )
.bool()) )
.executes( );
ctx ->
execute(
ctx,
BoolArgumentType
.getBool(
ctx,
"marker")))))));
} }
private static int execute(CommandContext<ServerCommandSource> ctx, boolean marker) { private static int execute(CommandContext<ServerCommandSource> ctx, boolean marker) {
@ -68,12 +60,8 @@ public class ChpCommand {
structure.placeCommand(world, pos, marker); structure.placeCommand(world, pos, marker);
source.sendFeedback( source.sendFeedback(
() -> () -> Text.literal("Placed structure '" + name + (marker ? "' with structure block" : "'")),
Text.literal( false);
"Placed structure '"
+ name
+ (marker ? "' with structure block" : "'")),
false);
return 1; return 1;
} }

View File

@ -11,9 +11,6 @@ public class ModEffects {
public static final StatusEffect CHIPI_BLESSING = new ChipiBlessingEffect(); public static final StatusEffect CHIPI_BLESSING = new ChipiBlessingEffect();
public static void register() { public static void register() {
Registry.register( Registry.register(Registries.STATUS_EFFECT, new Identifier(ChipiMod.MOD_ID, "chipi_blessing"), CHIPI_BLESSING);
Registries.STATUS_EFFECT,
new Identifier(ChipiMod.MOD_ID, "chipi_blessing"),
CHIPI_BLESSING);
} }
} }

View File

@ -11,14 +11,14 @@ import net.minecraft.util.Identifier;
public class ModEntities { public class ModEntities {
public static final EntityType<MepEntity> MEP = public static final EntityType<MepEntity> MEP = Registry.register(
Registry.register( Registries.ENTITY_TYPE,
Registries.ENTITY_TYPE, new Identifier(ChipiMod.MOD_ID, "mep"),
new Identifier(ChipiMod.MOD_ID, "mep"), FabricEntityTypeBuilder.createMob()
FabricEntityTypeBuilder.createMob() .entityFactory(MepEntity::new)
.entityFactory(MepEntity::new) .dimensions(EntityDimensions.fixed(0.6f, 1.95f))
.dimensions(EntityDimensions.fixed(0.6f, 1.95f)) .build()
.build()); );
public static void register() { public static void register() {
// called from mod init // called from mod init

View File

@ -37,21 +37,21 @@ public class MepEntity extends PathAwareEntity {
this.goalSelector.add(5, new LookAroundGoal(this)); this.goalSelector.add(5, new LookAroundGoal(this));
this.targetSelector.add( this.targetSelector.add(
1, 1,
new ActiveTargetGoal<>( new ActiveTargetGoal<>(
this, this,
PlayerEntity.class, PlayerEntity.class,
true, true,
target -> target -> target instanceof PlayerEntity player && (angryAtPlayer || !isPlayerProtected(player))
target instanceof PlayerEntity player )
&& (angryAtPlayer || !isPlayerProtected(player)))); );
} }
public static DefaultAttributeContainer.Builder createMepAttributes() { public static DefaultAttributeContainer.Builder createMepAttributes() {
return PathAwareEntity.createMobAttributes() return PathAwareEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 20.0) .add(EntityAttributes.GENERIC_MAX_HEALTH, 20.0)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 4.0) .add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 4.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.25); .add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.25);
} }
@Override @Override

View File

@ -4,6 +4,5 @@ import net.minecraft.item.FoodComponent;
public class ModFoodComponents { public class ModFoodComponents {
public static final FoodComponent NUT = public static final FoodComponent NUT = new FoodComponent.Builder().hunger(4).saturationModifier(0.3f).snack().build();
new FoodComponent.Builder().hunger(4).saturationModifier(0.3f).snack().build();
} }

View File

@ -12,37 +12,35 @@ import net.minecraft.util.Identifier;
public class ModItemGroups { public class ModItemGroups {
public static final ItemGroup CHIPI_GROUP = public static final ItemGroup CHIPI_GROUP = Registry.register(
Registry.register( Registries.ITEM_GROUP,
Registries.ITEM_GROUP, new Identifier(ChipiMod.MOD_ID, "chipi"),
new Identifier(ChipiMod.MOD_ID, "chipi"), FabricItemGroup.builder()
FabricItemGroup.builder() .displayName(Text.translatable("itemGroup.chipi.chipi"))
.displayName(Text.translatable("itemGroup.chipi.chipi")) .icon(() -> new ItemStack(ModBlocks.VOID_BLOCK.asItem()))
.icon(() -> new ItemStack(ModBlocks.VOID_BLOCK.asItem())) .entries((context, entries) -> {
.entries( // Blocks
(context, entries) -> { entries.add(ModBlocks.VOID_BLOCK);
entries.add(ModBlocks.CHIPPER_FRAME);
entries.add(ModBlocks.CHIPPER_PORTAL);
entries.add(ModBlocks.CHIPPER_ORE);
entries.add(ModBlocks.CHIPPER_ALLOY_BLOCK);
// Blocks // Items
entries.add(ModBlocks.VOID_BLOCK); entries.add(ModItems.NUT);
entries.add(ModBlocks.CHIPPER_FRAME); entries.add(ModItems.RAW_CHIPPER_ORE);
entries.add(ModBlocks.CHIPPER_PORTAL); entries.add(ModItems.CHIPPER_INGOT);
entries.add(ModBlocks.CHIPPER_ORE); entries.add(ModItems.CHIPPER_ALLOY);
entries.add(ModBlocks.CHIPPER_ALLOY_BLOCK); entries.add(ModItems.MEP_SPAWN_EGG);
// Items // Armor
entries.add(ModItems.NUT); entries.add(ModItems.CHIPPER_HELMET);
entries.add(ModItems.RAW_CHIPPER_ORE); entries.add(ModItems.CHIPPER_CHESTPLATE);
entries.add(ModItems.CHIPPER_INGOT); entries.add(ModItems.CHIPPER_LEGGINGS);
entries.add(ModItems.CHIPPER_ALLOY); entries.add(ModItems.CHIPPER_BOOTS);
entries.add(ModItems.MEP_SPAWN_EGG); })
.build()
// Armor );
entries.add(ModItems.CHIPPER_HELMET);
entries.add(ModItems.CHIPPER_CHESTPLATE);
entries.add(ModItems.CHIPPER_LEGGINGS);
entries.add(ModItems.CHIPPER_BOOTS);
})
.build());
public static void register() { public static void register() {
// force class load // force class load

View File

@ -17,102 +17,90 @@ public class ModItems {
// ===== BLOCK ITEMS ===== // ===== BLOCK ITEMS =====
public static final Item VOID_BLOCK = public static final Item VOID_BLOCK = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier(ChipiMod.MOD_ID, "void_block"),
new Identifier(ChipiMod.MOD_ID, "void_block"), new BlockItem(ModBlocks.VOID_BLOCK, new FabricItemSettings())
new BlockItem(ModBlocks.VOID_BLOCK, new FabricItemSettings())); );
public static final Item CHIPPER_FRAME = public static final Item CHIPPER_FRAME = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier(ChipiMod.MOD_ID, "chipper_frame"),
new Identifier(ChipiMod.MOD_ID, "chipper_frame"), new BlockItem(ModBlocks.CHIPPER_FRAME, new FabricItemSettings())
new BlockItem(ModBlocks.CHIPPER_FRAME, new FabricItemSettings())); );
public static final Item CHIPPER_PORTAL = public static final Item CHIPPER_PORTAL = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier(ChipiMod.MOD_ID, "chipper_portal"),
new Identifier(ChipiMod.MOD_ID, "chipper_portal"), new BlockItem(ModBlocks.CHIPPER_PORTAL, new FabricItemSettings())
new BlockItem(ModBlocks.CHIPPER_PORTAL, new FabricItemSettings())); );
public static final Item CHIPPER_ORE = public static final Item CHIPPER_ORE = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier(ChipiMod.MOD_ID, "chipper_ore"),
new Identifier(ChipiMod.MOD_ID, "chipper_ore"), new BlockItem(ModBlocks.CHIPPER_ORE, new FabricItemSettings())
new BlockItem(ModBlocks.CHIPPER_ORE, new FabricItemSettings())); );
public static final Item CHIPPER_ALLOY_BLOCK = public static final Item CHIPPER_ALLOY_BLOCK = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier(ChipiMod.MOD_ID, "chipper_alloy_block"),
new Identifier(ChipiMod.MOD_ID, "chipper_alloy_block"), new BlockItem(ModBlocks.CHIPPER_ALLOY_BLOCK, new FabricItemSettings())
new BlockItem(ModBlocks.CHIPPER_ALLOY_BLOCK, new FabricItemSettings())); );
public static final Item MEP_SPAWN_EGG = public static final Item MEP_SPAWN_EGG = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier(ChipiMod.MOD_ID, "mep_spawn_egg"),
new Identifier(ChipiMod.MOD_ID, "mep_spawn_egg"), new SpawnEggItem(ModEntities.MEP, 0x1E3A5F, 0x6BB6FF, new Item.Settings())
new SpawnEggItem(ModEntities.MEP, 0x1E3A5F, 0x6BB6FF, new Item.Settings())); );
// ===== NORMAL ITEMS ===== // ===== NORMAL ITEMS =====
public static final Item NUT = public static final Item NUT = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier(ChipiMod.MOD_ID, "nut"),
new Identifier(ChipiMod.MOD_ID, "nut"), new Item(new FabricItemSettings().food(ModFoodComponents.NUT))
new Item(new FabricItemSettings().food(ModFoodComponents.NUT))); );
public static final Item RAW_CHIPPER_ORE = public static final Item RAW_CHIPPER_ORE = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier(ChipiMod.MOD_ID, "raw_chipper_ore"),
new Identifier(ChipiMod.MOD_ID, "raw_chipper_ore"), new Item(new FabricItemSettings())
new Item(new FabricItemSettings())); );
public static final Item CHIPPER_INGOT = public static final Item CHIPPER_INGOT = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier(ChipiMod.MOD_ID, "chipper_ingot"),
new Identifier(ChipiMod.MOD_ID, "chipper_ingot"), new Item(new FabricItemSettings())
new Item(new FabricItemSettings())); );
public static final Item CHIPPER_ALLOY = public static final Item CHIPPER_ALLOY = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier(ChipiMod.MOD_ID, "chipper_alloy"),
new Identifier(ChipiMod.MOD_ID, "chipper_alloy"), new Item(new FabricItemSettings())
new Item(new FabricItemSettings())); );
public static final Item CHIPPER_HELMET = public static final Item CHIPPER_HELMET = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier("chipi", "chipper_helmet"),
new Identifier("chipi", "chipper_helmet"), new ArmorItem(ChipperArmorMaterial.INSTANCE, ArmorItem.Type.HELMET, new Item.Settings())
new ArmorItem( );
ChipperArmorMaterial.INSTANCE,
ArmorItem.Type.HELMET,
new Item.Settings()));
public static final Item CHIPPER_CHESTPLATE = public static final Item CHIPPER_CHESTPLATE = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier("chipi", "chipper_chestplate"),
new Identifier("chipi", "chipper_chestplate"), new ArmorItem(ChipperArmorMaterial.INSTANCE, ArmorItem.Type.CHESTPLATE, new Item.Settings())
new ArmorItem( );
ChipperArmorMaterial.INSTANCE,
ArmorItem.Type.CHESTPLATE,
new Item.Settings()));
public static final Item CHIPPER_LEGGINGS = public static final Item CHIPPER_LEGGINGS = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier("chipi", "chipper_leggings"),
new Identifier("chipi", "chipper_leggings"), new ArmorItem(ChipperArmorMaterial.INSTANCE, ArmorItem.Type.LEGGINGS, new Item.Settings())
new ArmorItem( );
ChipperArmorMaterial.INSTANCE,
ArmorItem.Type.LEGGINGS,
new Item.Settings()));
public static final Item CHIPPER_BOOTS = public static final Item CHIPPER_BOOTS = Registry.register(
Registry.register( Registries.ITEM,
Registries.ITEM, new Identifier("chipi", "chipper_boots"),
new Identifier("chipi", "chipper_boots"), new ArmorItem(ChipperArmorMaterial.INSTANCE, ArmorItem.Type.BOOTS, new Item.Settings())
new ArmorItem( );
ChipperArmorMaterial.INSTANCE,
ArmorItem.Type.BOOTS,
new Item.Settings()));
public static void register() {} public static void register() {}
} }

View File

@ -1,5 +1,6 @@
package net.Chipperfluff.chipi.item.armor; package net.Chipperfluff.chipi.item.armor;
import net.Chipperfluff.chipi.item.ModItems;
import net.minecraft.item.ArmorItem; import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial; import net.minecraft.item.ArmorMaterial;
import net.minecraft.recipe.Ingredient; import net.minecraft.recipe.Ingredient;
@ -14,15 +15,15 @@ public class ChipperArmorMaterial implements ArmorMaterial {
public static final ChipperArmorMaterial INSTANCE = new ChipperArmorMaterial(); public static final ChipperArmorMaterial INSTANCE = new ChipperArmorMaterial();
private static final Map<ArmorItem.Type, Integer> PROTECTION = private static final Map<ArmorItem.Type, Integer> PROTECTION = Util.make(
Util.make( new EnumMap<>(ArmorItem.Type.class),
new EnumMap<>(ArmorItem.Type.class), map -> {
map -> { map.put(ArmorItem.Type.HELMET, 2);
map.put(ArmorItem.Type.HELMET, 2); map.put(ArmorItem.Type.CHESTPLATE, 5);
map.put(ArmorItem.Type.CHESTPLATE, 5); map.put(ArmorItem.Type.LEGGINGS, 4);
map.put(ArmorItem.Type.LEGGINGS, 4); map.put(ArmorItem.Type.BOOTS, 2);
map.put(ArmorItem.Type.BOOTS, 2); }
}); );
@Override @Override
public int getDurability(ArmorItem.Type type) { public int getDurability(ArmorItem.Type type) {
@ -46,7 +47,7 @@ public class ChipperArmorMaterial implements ArmorMaterial {
@Override @Override
public Ingredient getRepairIngredient() { public Ingredient getRepairIngredient() {
return Ingredient.ofItems(net.Chipperfluff.chipi.item.ModItems.CHIPPER_INGOT); return Ingredient.ofItems(ModItems.CHIPPER_INGOT);
} }
@Override @Override

View File

@ -161,8 +161,7 @@ public class ChipiDungeonGenerator {
runInChipi(world, "fill 5 91 16 5 91 15 minecraft:deepslate_tiles"); runInChipi(world, "fill 5 91 16 5 91 15 minecraft:deepslate_tiles");
} }
private static void fillBox( private static void fillBox(ServerWorld world, int x1, int y1, int z1, int x2, int y2, int z2, BlockState state) {
ServerWorld world, int x1, int y1, int z1, int x2, int y2, int z2, BlockState state) {
int minX = Math.min(x1, x2); int minX = Math.min(x1, x2);
int maxX = Math.max(x1, x2); int maxX = Math.max(x1, x2);
int minY = Math.min(y1, y2); int minY = Math.min(y1, y2);
@ -187,8 +186,7 @@ public class ChipiDungeonGenerator {
"execute in chipi:chipi_dimension run " + command); "execute in chipi:chipi_dimension run " + command);
} }
private static DungeonContext ctx( private static DungeonContext ctx(ServerWorld world, int gridX, int gridY, BlockPos origin, ChipiStructure structure) {
ServerWorld world, int gridX, int gridY, BlockPos origin, ChipiStructure structure) {
return DungeonContext.of(world, gridX, gridY, origin, structure); return DungeonContext.of(world, gridX, gridY, origin, structure);
} }
} }

View File

@ -1,8 +1,6 @@
package net.Chipperfluff.chipi.world.gen; package net.Chipperfluff.chipi.world.gen;
import java.util.Optional; import java.util.Optional;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.StructureBlockBlockEntity; import net.minecraft.block.entity.StructureBlockBlockEntity;
import net.minecraft.block.enums.StructureBlockMode; import net.minecraft.block.enums.StructureBlockMode;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
@ -11,6 +9,7 @@ import net.minecraft.structure.StructureTemplate;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
import net.minecraft.block.Blocks;
public abstract class ChipiStructure { public abstract class ChipiStructure {
@ -33,23 +32,22 @@ public abstract class ChipiStructure {
return new BlockPos(size.getX(), size.getY(), size.getZ()); return new BlockPos(size.getX(), size.getY(), size.getZ());
} }
public void placeAt(ServerWorld world, BlockPos centerPos) { public void placeAt(ServerWorld world, BlockPos structureOrigin) {
Optional<StructureTemplate> opt = world.getStructureTemplateManager().getTemplate(id); Optional<StructureTemplate> opt = world.getStructureTemplateManager().getTemplate(id);
if (opt.isEmpty()) { if (opt.isEmpty()) {
System.out.println("[CHIPI] Missing structure: " + id); System.out.println("[CHIPI] Missing structure: " + id);
return; return;
} }
BlockPos origin = centerPos.add(deltaX, deltaY, deltaZ); BlockPos origin = structureOrigin.add(deltaX, deltaY, deltaZ);
opt.get().place(world, origin, origin, new StructurePlacementData(), world.getRandom(), 2); opt.get().place(world, origin, origin, new StructurePlacementData(), world.getRandom(), 2);
} }
public void placeCommand(ServerWorld world, BlockPos placePos, boolean marker) { public void placeCommand(ServerWorld world, BlockPos structureOrigin, boolean marker) {
placeAt(world, placePos); placeAt(world, structureOrigin);
if (!marker) return; if (!marker) return;
BlockPos origin = placePos.add(deltaX, deltaY, deltaZ); BlockPos origin = structureOrigin.add(deltaX, deltaY, deltaZ);
world.setBlockState(origin, Blocks.STRUCTURE_BLOCK.getDefaultState(), 3); world.setBlockState(origin, Blocks.STRUCTURE_BLOCK.getDefaultState(), 3);
if (world.getBlockEntity(origin) instanceof StructureBlockBlockEntity be) { if (world.getBlockEntity(origin) instanceof StructureBlockBlockEntity be) {
@ -63,47 +61,7 @@ public abstract class ChipiStructure {
} }
} }
public BlockPos local(BlockPos centerPos, BlockPos localPos) { public BlockPos localToWorld(BlockPos structureOrigin, BlockPos localPos) {
return centerPos.add(deltaX + localPos.getX(), deltaY + localPos.getY(), deltaZ + localPos.getZ()); return structureOrigin.add(deltaX + localPos.getX(), deltaY + localPos.getY(), deltaZ + localPos.getZ());
}
public void setBlock(
ServerWorld world,
BlockPos centerPos,
BlockPos localPos,
BlockState state,
Integer gridX,
Integer gridY) {
BlockPos worldPos = local(centerPos, localPos);
System.out.println(
"[CHIPI] setBlock grid=("
+ gridX
+ ","
+ gridY
+ ") worldPos="
+ worldPos);
world.setBlockState(worldPos, state, 3);
}
public void fillBlocks(
ServerWorld world,
BlockPos centerPos,
BlockPos from,
BlockPos to,
BlockState state,
Integer gridX,
Integer gridY) {
BlockPos start = local(centerPos, from);
BlockPos end = local(centerPos, to);
System.out.println(
"[CHIPI] fillBlocks grid=("
+ gridX
+ ","
+ gridY
+ ") from="
+ start
+ " to="
+ end);
BlockPos.stream(start, end).forEach(pos -> world.setBlockState(pos, state, 3));
} }
} }

View File

@ -1,5 +1,6 @@
package net.Chipperfluff.chipi.world.gen; package net.Chipperfluff.chipi.world.gen;
import net.minecraft.block.BlockState;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -39,11 +40,20 @@ public final class DungeonContext {
return grid_y; return grid_y;
} }
public BlockPos getStructureOrigin() {
return structure_origin;
}
public ChipiStructure getStructure() { public ChipiStructure getStructure() {
return structure; return structure;
} }
public void setBlock(BlockPos localPos, BlockState state) {
BlockPos worldPos = structure.localToWorld(structure_origin, localPos);
System.out.println("[CHIPI] setBlock grid=(" + grid_x + "," + grid_y + ") worldPos=" + worldPos);
world.setBlockState(worldPos, state, 3);
}
public void fillBlocks(BlockPos from, BlockPos to, BlockState state) {
BlockPos start = structure.localToWorld(structure_origin, from);
BlockPos end = structure.localToWorld(structure_origin, to);
System.out.println("[CHIPI] fillBlocks grid=(" + grid_x + "," + grid_y + ") from=" + start + " to=" + end);
BlockPos.stream(start, end).forEach(pos -> world.setBlockState(pos, state, 3));
}
} }

View File

@ -37,14 +37,7 @@ public final class WorldMaster {
public static RoomBaseStructure afterPlaceRoom(DungeonContext ctx) { public static RoomBaseStructure afterPlaceRoom(DungeonContext ctx) {
if (ctx.getGridX() == 1 && ctx.getGridY() == 1) { if (ctx.getGridX() == 1 && ctx.getGridY() == 1) {
ctx.getStructure().setBlock( ctx.setBlock(new BlockPos(0, 0, 0), Blocks.REDSTONE_BLOCK.getDefaultState());
ctx.getWorld(),
ctx.getStructureOrigin(),
new BlockPos(0, 0, 0),
Blocks.REDSTONE_BLOCK.getDefaultState(),
ctx.getGridX(),
ctx.getGridY()
);
} }
return getDefaultRoom(); return getDefaultRoom();