Create Ore Excavation

Create Ore Excavation

10M Downloads

When using the setvein command, the single-player game will exit and exiting the world without doing anything after you use the command will cause the vein you just generated to disappear in MC1.21.1- Neoforge21.1.143 with create version 6.0.4.

Closed this issue · 0 comments

commented

When I try to use the "coe setvein" command in a single-player game in MC1.21.1- Neoforge21.1.143, I immediately exit single-player mode with error message: "Internal Exception: io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:system_chat"(picture below). So I tried to look at the source code, and I found that rl.id() in the translatable method on line 55(line 13 below) of COECommand.java passed in a ResourceLocation object, which should actually be a String. This invalidates the “setvein” command and causes a program error. I successfully used the “setvein” command in single-player mode after I changing it to rl.id().toString ().

Image

But in my subsequent testing, I found that although the setvein command appears to work, it does not really realize the function of generating veins. At the time of using “Ore Vein Finder”, I can see that there are veins generated in this chunk, but once I exit and re-enter, it will return to the state of no veins. The only way to turn a block into a vein is to use the setvein command and immediately build a “Drilling machine” on the block.(This may be a mod feature?)

I am currently a university student in China, majoring in computer related studies. Playing minecraft is just one of my intersts, and I really like this mod. Therefore, I hope to submit this issue to improve it while also providing me with an opportunity to enhance my skills. This is my first time submitting an issue, and I sincerely appreciate your understanding and patience if there are any mistakes.

Image Image
public static void init() {}

public static void register(RegisterCommandsEvent evt) {
	LiteralArgumentBuilder<CommandSourceStack> l = Commands.literal("coe");
	l.then(Commands.literal("setvein").requires(s -> s.hasPermission(2)).
			then(Commands.argument("pos", BlockPosArgument.blockPos()).
					then(Commands.argument("recipe", ResourceLocationArgument.id()).suggests(ALL_RECIPES).
							executes(c -> {
								BlockPos p = BlockPosArgument.getLoadedBlockPos(c, "pos");
								RecipeHolder<?> rl = ResourceLocationArgument.getRecipe(c, "recipe");
								if(rl.value() instanceof VeinRecipe) {
									setVein(c.getSource(), p, rl.id(), 0.8F);
									c.getSource().sendSuccess(() -> Component.translatable("command.coe.setvein.success", rl.id()), true);        //here is the problem.
									return 1;
								}
								return 0;
							}).
							then(Commands.argument("multiplier", FloatArgumentType.floatArg(0, 1000)).
									executes(c -> {
										float mul = FloatArgumentType.getFloat(c, "multiplier");
										BlockPos p = BlockPosArgument.getLoadedBlockPos(c, "pos");
										RecipeHolder<?> rl = ResourceLocationArgument.getRecipe(c, "recipe");
										if(rl.value() instanceof VeinRecipe) {
											setVein(c.getSource(), p, rl.id(), mul);
											c.getSource().sendSuccess(() -> Component.translatable("command.coe.setvein.success", rl.id()), true);
											return 1;
										}
										return 0;
									})
									)
							)
					)
			);
	l.then(Commands.literal("removevein").requires(s -> s.hasPermission(2)).
			then(Commands.argument("pos", BlockPosArgument.blockPos()).
					executes(c -> {
						BlockPos p = BlockPosArgument.getLoadedBlockPos(c, "pos");
						setVein(c.getSource(), p, null, 0F);
						c.getSource().sendSuccess(() -> Component.translatable("command.coe.setvein.success", Component.translatable("chat.coe.veinFinder.nothing")), true);
						return 1;
					})
					)
			);
	l.then(Commands.literal("locate").requires(s -> s.hasPermission(2)).
			then(Commands.argument("recipe", ResourceLocationArgument.id()).suggests(ALL_RECIPES).
					executes(c -> {
						RecipeHolder<?> rl = ResourceLocationArgument.getRecipe(c, "recipe");
						if(rl.value() instanceof VeinRecipe) {
							BlockPos blockpos = BlockPos.containing(c.getSource().getPosition());
							Stopwatch stopwatch = Stopwatch.createStarted(Util.TICKER);
							BlockPos at = OreVeinGenerator.getPicker(c.getSource().getLevel()).locate(rl.id(), blockpos, c.getSource().getLevel(), 100);
							stopwatch.stop();
							if(at != null) {
								int i = Mth.floor(RandomSpreadGenerator.distance2d(at, blockpos));
								Component component = ComponentUtils.wrapInSquareBrackets(Component.translatable("chat.coordinates", at.getX(), "~", at.getZ())).withStyle((p_214489_) -> {
									return p_214489_.withColor(ChatFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tp @s " + at.getX() + " ~ " + at.getZ())).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable("chat.coordinates.tooltip")));
								});
								c.getSource().sendSuccess(() -> {
									return Component.translatable("command.coe.locate.success", rl.id().toString(), component, i);
								}, false);
								CreateOreExcavation.LOGGER.info("Locating element " + rl.id() + " took " + stopwatch.elapsed().toMillis() + " ms");
								return i;
							} else {
								throw ERROR_VEIN_NOT_FOUND.create(rl.id().toString());
							}
						} else {
							throw ERROR_VEIN_NOT_FOUND.create(rl.id().toString());
						}
					})
					)
			);
	evt.getDispatcher().register(l);
}

private static void setVein(CommandSourceStack css, BlockPos pos, ResourceLocation rl, float mul) {
	ChunkPos p = new ChunkPos(pos);
	OreData data = OreDataAttachment.getData(css.getLevel().getChunk(p.x, p.z));
	data.setRecipe(rl);
	data.setLoaded(true);
	data.setRandomMul(mul);
	data.setExtractedAmount(0);
}

}