Skip to content
This repository was archived by the owner on Apr 17, 2026. It is now read-only.

Commit 9b76b3d

Browse files
authored
Merge pull request #84 from o7Moon/83-boat-collision
implement collision modes
2 parents eff77e6 + dee15ee commit 9b76b3d

9 files changed

Lines changed: 70 additions & 8 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ minecraft_version_allowed_range=>=1.20.1 <=1.20.4
77
yarn_mappings=1.20.1+build.10
88
loader_version=0.15.11
99
# Mod Properties
10-
mod_version=0.4.2_1.20.1-1.20.4
10+
mod_version=0.4.3_1.20.1-1.20.4
1111
maven_group=dev.o7moon
1212
archives_base_name=OpenBoatUtils
1313
# Dependencies

src/main/java/dev/o7moon/openboatutils/ClientboundPackets.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ public enum ClientboundPackets {
3636
CLEAR_SLIPPERINESS,
3737
MODE_SERIES,
3838
EXCLUSIVE_MODE_SERIES,
39-
SET_PER_BLOCK;
39+
SET_PER_BLOCK,
40+
SET_COLLISION_MODE;
4041

4142
public static void registerCodecs() {
4243
//? >=1.21 {
43-
/*PayloadTypeRegistry.playS2C().register(OpenBoatUtils.BytePayload.ID, OpenBoatUtils.BytePayload.CODEC);*/
44-
//? }
44+
/*PayloadTypeRegistry.playS2C().register(OpenBoatUtils.BytePayload.ID, OpenBoatUtils.BytePayload.CODEC);
45+
*///?}
4546
}
4647

4748
public static void registerHandlers(){
@@ -180,6 +181,10 @@ public static void handlePacket(PacketByteBuf buf) {
180181
blocksArray = blocks.split(",");
181182
OpenBoatUtils.setBlocksSetting(OpenBoatUtils.PerBlockSettingType.values()[setting], Arrays.asList(blocksArray), value);
182183
return;
184+
case 27:
185+
short cmode = buf.readShort();
186+
OpenBoatUtils.setCollisionMode(CollisionMode.values()[cmode]);
187+
return;
183188
}
184189
} catch (Exception E) {
185190
OpenBoatUtils.LOG.error("Error when handling clientbound openboatutils packet: ");
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dev.o7moon.openboatutils;
2+
3+
public enum CollisionMode {
4+
VANILLA,// 0
5+
NO_BOATS_OR_PLAYERS,// 1
6+
NO_ENTITIES;// 2
7+
}

src/main/java/dev/o7moon/openboatutils/Modes.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public enum Modes {
2323
BOOSTER_BLOCKS,//17
2424
DEFAULT_ICE,//18
2525
DEFAULT_BLUE_ICE,//19
26+
NOCOL_BOATS_AND_PLAYERS,//20
27+
NOCOL_ALL_ENTITIES,//21
2628
;
2729

2830
public static void setMode(Modes mode) {
@@ -155,6 +157,12 @@ public static void setMode(Modes mode) {
155157
case DEFAULT_BLUE_ICE:
156158
OpenBoatUtils.setAllBlocksSlipperiness(0.985f);
157159
return;
160+
case NOCOL_BOATS_AND_PLAYERS:
161+
OpenBoatUtils.setCollisionMode(CollisionMode.NO_BOATS_OR_PLAYERS);
162+
return;
163+
case NOCOL_ALL_ENTITIES:
164+
OpenBoatUtils.setCollisionMode(CollisionMode.NO_ENTITIES);
165+
return;
158166
}
159167
}
160168
}

src/main/java/dev/o7moon/openboatutils/OpenBoatUtils.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void onInitialize() {
4444

4545
public static final Logger LOG = LoggerFactory.getLogger("OpenBoatUtils");
4646

47-
public static final int VERSION = 9;
47+
public static final int VERSION = 10;
4848

4949
public static final Identifier settingsChannel = Identifier.of("openboatutils","settings");
5050

@@ -67,6 +67,7 @@ public void onInitialize() {
6767
public static int coyoteTimer = 0;// timer decrements per tick, is reset to time when grounded
6868
public static boolean waterJumping = false;
6969
public static float swimForce = 0.0f;
70+
public static CollisionMode collision = CollisionMode.VANILLA;
7071

7172
public static HashMap<String, Float> vanillaSlipperinessMap;
7273

@@ -172,6 +173,7 @@ public static void resetSettings(){
172173
swimForce = 0.0f;
173174
slipperinessMap = new HashMap<>(getVanillaSlipperinessMap());
174175
perBlockSettings = new HashMap<>();
176+
collision = CollisionMode.VANILLA;
175177
}
176178

177179
public static void setStepSize(float stepsize){
@@ -386,4 +388,13 @@ public static void setBlockSetting(PerBlockSettingType setting, String block, fl
386388
blocks.add(block);
387389
setBlocksSetting(setting, blocks, value);
388390
}
391+
392+
public static void setCollisionMode(CollisionMode mode) {
393+
enabled = true;
394+
collision = mode;
395+
}
396+
397+
public static CollisionMode getCollisionMode() {
398+
return collision;
399+
}
389400
}

src/main/java/dev/o7moon/openboatutils/ServerboundPackets.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public enum ServerboundPackets {
1010

1111
public static void registerCodecs() {
1212
//? >=1.21 {
13-
/*PayloadTypeRegistry.playC2S().register(OpenBoatUtils.BytePayload.ID, OpenBoatUtils.BytePayload.CODEC);*/
14-
//? }
13+
/*PayloadTypeRegistry.playC2S().register(OpenBoatUtils.BytePayload.ID, OpenBoatUtils.BytePayload.CODEC);
14+
*///?}
1515
}
1616

1717
public static void registerHandlers(){

src/main/java/dev/o7moon/openboatutils/SingleplayerCommands.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,19 @@ public static void registerCommands(){
411411
return 1;
412412
}))))
413413
);
414+
415+
dispatcher.register(
416+
literal("collisionmode").then(argument("ID", IntegerArgumentType.integer(0,2)).executes(ctx -> {
417+
ServerPlayerEntity player = ctx.getSource().getPlayer();
418+
if (player == null) return 0;
419+
PacketByteBuf packet = PacketByteBufs.create();
420+
packet.writeShort(ClientboundPackets.SET_COLLISION_MODE.ordinal());
421+
packet.writeShort(IntegerArgumentType.getInteger(ctx, "ID"));
422+
OpenBoatUtils.sendPacketS2C(player, packet);
423+
return 1;
424+
})
425+
)
426+
);
414427
});
415428
}
416429
}

src/main/java/dev/o7moon/openboatutils/mixin/BoatMixin.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.o7moon.openboatutils.mixin;
22

3+
import dev.o7moon.openboatutils.CollisionMode;
34
import dev.o7moon.openboatutils.GetStepHeight;
45
import dev.o7moon.openboatutils.OpenBoatUtils;
56
import net.minecraft.block.Block;
@@ -147,6 +148,23 @@ float getFriction(Block block) {
147148
return OpenBoatUtils.getBlockSlipperiness(Registries.BLOCK.getId(block).toString());
148149
}
149150

151+
@Inject(method = "collidesWith", at = @At("HEAD"), cancellable = true)
152+
void canCollideHook(Entity other, CallbackInfoReturnable<Boolean> ci) {
153+
if (!OpenBoatUtils.enabled) return;
154+
CollisionMode mode = OpenBoatUtils.getCollisionMode();
155+
if (mode == CollisionMode.VANILLA) return;
156+
if (mode == CollisionMode.NO_BOATS_OR_PLAYERS && (other instanceof BoatEntity || other instanceof PlayerEntity)) {
157+
ci.setReturnValue(false);
158+
ci.cancel();
159+
return;
160+
}
161+
if (mode == CollisionMode.NO_ENTITIES) {
162+
ci.setReturnValue(false);
163+
ci.cancel();
164+
return;
165+
}
166+
}
167+
150168
@Inject(method = "fall", at = @At("HEAD"), cancellable = true)
151169
void fallHook(CallbackInfo ci) {
152170
if (!OpenBoatUtils.fallDamage) ci.cancel();

versions/1.21/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ minecraft_version_allowed_range=>=1.21 <=1.21.1
77
yarn_mappings=1.21+build.8
88
loader_version=0.15.11
99
# Mod Properties
10-
mod_version=0.4.2_1.21
10+
mod_version=0.4.3_1.21
1111
maven_group=dev.o7moon
1212
archives_base_name=OpenBoatUtils
1313
# Dependencies

0 commit comments

Comments
 (0)