Skip to content

Commit

Permalink
Release v1.20.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
EDToaster committed Oct 14, 2023
2 parents 8c47485 + 5162c8e commit da11abe
Show file tree
Hide file tree
Showing 108 changed files with 2,191 additions and 1,078 deletions.
5 changes: 5 additions & 0 deletions src/main/java/dev/murad/shipping/ShippingMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.murad.shipping.setup.ModMenuTypes;
import dev.murad.shipping.setup.Registration;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
Expand Down Expand Up @@ -52,4 +53,8 @@ private void doClientStuff(final FMLClientSetupEvent event) {

event.enqueueWork(ModItemModelProperties::register);
}

public static ResourceLocation entityTexture(String suffix) {
return new ResourceLocation(ShippingMod.MOD_ID, String.format("textures/entity/%s", suffix));
}
}
6 changes: 6 additions & 0 deletions src/main/java/dev/murad/shipping/block/rail/JunctionRail.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,10 @@ public RailShape getVanillaRailShapeFromDirection(BlockState state, BlockPos pos
public boolean isAutomaticSwitching() {
return false;
}

@Deprecated
@Override
public boolean isValidRailShape(RailShape shape) {
return RAIL_SHAPE.getPossibleValues().contains(shape);
}
}
5 changes: 5 additions & 0 deletions src/main/java/dev/murad/shipping/block/rail/SwitchRail.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,9 @@ public void neighborChanged(BlockState state, Level world, BlockPos pos, Block p
public boolean canConnectRedstone(BlockState state, BlockGetter world, BlockPos pos, @javax.annotation.Nullable Direction side) {
return true;
}

@Override
public boolean isValidRailShape(RailShape shape) {
return RAIL_SHAPE.getPossibleValues().contains(shape);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,10 @@ public void neighborChanged(BlockState state, Level world, BlockPos pos, Block p
public boolean canConnectRedstone(BlockState state, BlockGetter world, BlockPos pos, @javax.annotation.Nullable Direction side) {
return true;
}

@Deprecated
@Override
public boolean isValidRailShape(RailShape shape) {
return RAIL_SHAPE.getPossibleValues().contains(shape);
}
}
27 changes: 27 additions & 0 deletions src/main/java/dev/murad/shipping/data/ModRecipeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,24 @@ protected void buildRecipes(Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_item", has(Items.CHEST))
.save(consumer);

ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, ModItems.BARREL_BARGE.get())
.define('_', Items.BARREL)
.define('#', Items.STICK)
.define('$', Items.IRON_INGOT)
.pattern("#_#")
.pattern("$$$")
.unlockedBy("has_item", has(Items.BARREL))
.save(consumer);

ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, ModItems.VACUUM_BARGE.get())
.define('_', Items.HOPPER)
.define('#', Items.ENDER_EYE)
.define('$', Items.IRON_INGOT)
.pattern("#_#")
.pattern("$$$")
.unlockedBy("has_item", has(Items.HOPPER))
.save(consumer);

ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, ModItems.SEATER_BARGE.get())
.define('_', ItemTags.WOODEN_STAIRS)
.define('#', ItemTags.SIGNS)
Expand Down Expand Up @@ -255,6 +273,15 @@ protected void buildRecipes(Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_item", has(ModItems.SEATER_CAR.get()))
.save(consumer);

ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, ModItems.BARREL_CAR.get())
.define('#', Items.BARREL)
.define('$', ModItems.SEATER_CAR.get())
.pattern(" ")
.pattern(" # ")
.pattern(" $ ")
.unlockedBy("has_item", has(ModItems.SEATER_CAR.get()))
.save(consumer);

ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, ModItems.FLUID_CAR.get())
.define('#', Items.GLASS)
.define('$', ModItems.SEATER_CAR.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ protected void registerModels() {
withExistingParent("vessel_charger", modLoc("block/vessel_charger"));

builder(itemGenerated, "barge");
builder(itemGenerated, "barrel_barge");
builder(itemGenerated, "vacuum_barge");
builder(itemGenerated, "chunk_loader_barge");
builder(itemGenerated, "fishing_barge");
builder(itemGenerated, "fluid_barge");
Expand All @@ -37,6 +39,7 @@ protected void registerModels() {
builder(itemGenerated, "steam_locomotive");
builder(itemGenerated, "energy_locomotive");
builder(itemGenerated, "chest_car");
builder(itemGenerated, "barrel_car");
builder(itemGenerated, "chunk_loader_car");
builder(itemGenerated, "fluid_car");
builder(itemGenerated, "seater_car");
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dev/murad/shipping/entity/Colorable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.murad.shipping.entity;

import javax.annotation.Nullable;

public interface Colorable {
@Nullable
Integer getColor();

void setColor(@Nullable Integer color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@
import com.mojang.datafixers.util.Pair;
import dev.murad.shipping.ShippingConfig;
import dev.murad.shipping.capability.StallingCapability;
import dev.murad.shipping.entity.Colorable;
import dev.murad.shipping.entity.custom.train.locomotive.AbstractLocomotiveEntity;
import dev.murad.shipping.entity.custom.vessel.VesselEntity;
import dev.murad.shipping.setup.ModItems;
import dev.murad.shipping.util.LinkableEntity;
import dev.murad.shipping.util.LinkingHandler;
import dev.murad.shipping.util.RailHelper;
import dev.murad.shipping.util.Train;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameRules;
Expand All @@ -49,7 +56,9 @@
import java.util.stream.Stream;

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public abstract class AbstractTrainCarEntity extends AbstractMinecart implements IForgeAbstractMinecart, LinkableEntity<AbstractTrainCarEntity> {
public abstract class AbstractTrainCarEntity extends AbstractMinecart implements IForgeAbstractMinecart, LinkableEntity<AbstractTrainCarEntity>, Colorable {

public static final EntityDataAccessor<Integer> COLOR_DATA = SynchedEntityData.defineId(AbstractTrainCarEntity.class, EntityDataSerializers.INT);

public static final EntityDataAccessor<Integer> DOMINANT_ID = SynchedEntityData.defineId(AbstractTrainCarEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> DOMINATED_ID = SynchedEntityData.defineId(AbstractTrainCarEntity.class, EntityDataSerializers.INT);
Expand All @@ -62,7 +71,7 @@ public abstract class AbstractTrainCarEntity extends AbstractMinecart implements
@Setter
private boolean frozen = false;

private static final Map<RailShape, Pair<Vec3i, Vec3i>> EXITS = Util.make(Maps.newEnumMap(RailShape.class), (p_38135_) -> {
private static final Map<RailShape, Pair<Vec3i, Vec3i>> EXITS = Util.make(Maps.newEnumMap(RailShape.class), (enumMap) -> {
Vec3i west = Direction.WEST.getNormal();
Vec3i east = Direction.EAST.getNormal();
Vec3i north = Direction.NORTH.getNormal();
Expand All @@ -71,16 +80,16 @@ public abstract class AbstractTrainCarEntity extends AbstractMinecart implements
Vec3i eastUnder = east.below();
Vec3i northUnder = north.below();
Vec3i southUnder = south.below();
p_38135_.put(RailShape.NORTH_SOUTH, Pair.of(north, south));
p_38135_.put(RailShape.EAST_WEST, Pair.of(west, east));
p_38135_.put(RailShape.ASCENDING_EAST, Pair.of(westUnder, east));
p_38135_.put(RailShape.ASCENDING_WEST, Pair.of(west, eastUnder));
p_38135_.put(RailShape.ASCENDING_NORTH, Pair.of(north, southUnder));
p_38135_.put(RailShape.ASCENDING_SOUTH, Pair.of(northUnder, south));
p_38135_.put(RailShape.SOUTH_EAST, Pair.of(south, east));
p_38135_.put(RailShape.SOUTH_WEST, Pair.of(south, west));
p_38135_.put(RailShape.NORTH_WEST, Pair.of(north, west));
p_38135_.put(RailShape.NORTH_EAST, Pair.of(north, east));
enumMap.put(RailShape.NORTH_SOUTH, Pair.of(north, south));
enumMap.put(RailShape.EAST_WEST, Pair.of(west, east));
enumMap.put(RailShape.ASCENDING_EAST, Pair.of(westUnder, east));
enumMap.put(RailShape.ASCENDING_WEST, Pair.of(west, eastUnder));
enumMap.put(RailShape.ASCENDING_NORTH, Pair.of(north, southUnder));
enumMap.put(RailShape.ASCENDING_SOUTH, Pair.of(northUnder, south));
enumMap.put(RailShape.SOUTH_EAST, Pair.of(south, east));
enumMap.put(RailShape.SOUTH_WEST, Pair.of(south, west));
enumMap.put(RailShape.NORTH_WEST, Pair.of(north, west));
enumMap.put(RailShape.NORTH_EAST, Pair.of(north, east));
});

private static Pair<Vec3i, Vec3i> exits(RailShape pShape) {
Expand All @@ -91,10 +100,11 @@ public AbstractTrainCarEntity(EntityType<?> entityType, Level level) {
super(entityType, level);
linkingHandler.train = new Train<>(this);
railHelper = new RailHelper(this);
resetAttributes();
}

public AbstractTrainCarEntity(EntityType<?> p_38087_, Level level, double x, double y, double z) {
super(p_38087_, level, x, y, z);
public AbstractTrainCarEntity(EntityType<?> entityType, Level level, double x, double y, double z) {
super(entityType, level, x, y, z);
var pos = BlockPos.containing(x, y, z);
var state = level().getBlockState(pos);
if (state.getBlock() instanceof BaseRailBlock railBlock) {
Expand All @@ -104,6 +114,11 @@ public AbstractTrainCarEntity(EntityType<?> p_38087_, Level level, double x, dou
}
linkingHandler.train = new Train<>(this);
railHelper = new RailHelper(this);
resetAttributes();
}

private void resetAttributes() {
setCustomNameVisible(true);
}

protected Optional<RailShape> getRailShape() {
Expand All @@ -127,55 +142,64 @@ public boolean canBeCollidedWith() {
return getPickResult().getItem();
}

@Nullable
public Integer getColor() {
int color = this.getEntityData().get(COLOR_DATA);
return color == -1 ? null : color;
}

public void setColor(Integer color) {
if (color == null) color = -1;
this.getEntityData().set(COLOR_DATA, color);
}

@Override
public InteractionResult interact(Player player, InteractionHand hand) {
InteractionResult ret = super.interact(player, hand);
if (ret.consumesAction()) return ret;

var color = DyeColor.getColor(player.getItemInHand(hand));

if (color != null) {
if (!level().isClientSide) {
this.getEntityData().set(COLOR_DATA, color.getId());
}
// don't interact *and* use current item
return InteractionResult.sidedSuccess(this.level().isClientSide);
}

return InteractionResult.PASS;
}

@Override
protected void readAdditionalSaveData(@NotNull CompoundTag compound) {
super.readAdditionalSaveData(compound);

if (compound.contains("Color", Tag.TAG_INT)) {
setColor(compound.getInt("Color"));
}

linkingHandler.readAdditionalSaveData(compound);
}

@Override
protected void addAdditionalSaveData(@NotNull CompoundTag compound) {
super.addAdditionalSaveData(compound);
linkingHandler.addAdditionalSaveData(compound);

}

private Optional<AbstractTrainCarEntity> tryToLoadFromNBT(CompoundTag compound) {
try {
BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
pos.set(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"));
String uuid = compound.getString("UUID");
AABB searchBox = new AABB(
pos.getX() - 2,
pos.getY() - 2,
pos.getZ() - 2,
pos.getX() + 2,
pos.getY() + 2,
pos.getZ() + 2
);
List<Entity> entities = level().getEntities(this, searchBox, e -> e.getStringUUID().equals(uuid));
return entities.stream().findFirst().map(e -> (AbstractTrainCarEntity) e);
} catch (Exception e) {
return Optional.empty();
Integer color = getColor();
if (color != null) {
compound.putInt("Color", color);
}
}

private void writeNBT(Entity entity, CompoundTag globalCompound) {
CompoundTag compound = new CompoundTag();
compound.putInt("X", (int) Math.floor(entity.getX()));
compound.putInt("Y", (int) Math.floor(entity.getY()));
compound.putInt("Z", (int) Math.floor(entity.getZ()));

compound.putString("UUID", entity.getUUID().toString());

globalCompound.put("dominant", compound);
linkingHandler.addAdditionalSaveData(compound);
}

@Override
protected void defineSynchedData() {
super.defineSynchedData();
getEntityData().define(DOMINANT_ID, -1);
getEntityData().define(DOMINATED_ID, -1);
getEntityData().define(COLOR_DATA, -1);
}


Expand Down Expand Up @@ -454,7 +478,13 @@ public void destroy(@NotNull DamageSource pSource) {
int i = (int) Stream.of(linkingHandler.leader, linkingHandler.follower).filter(Optional::isPresent).count();
this.remove(Entity.RemovalReason.KILLED);
if (this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
this.spawnAtLocation(this.getPickResult());
var stack = this.getPickResult();

if (this.hasCustomName()) {
stack.setHoverName(this.getCustomName());
}

this.spawnAtLocation(stack);
for (int j = 0; j < i; j++) {
spawnChain();
}
Expand Down Expand Up @@ -684,6 +714,7 @@ private static void createLinks(AbstractTrainCarEntity dominant, AbstractTrainCa
}

@Override
@NonNull
public abstract ItemStack getPickResult();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public void remove(RemovalReason r) {

@Override
public InteractionResult interact(Player pPlayer, InteractionHand pHand) {

InteractionResult ret = super.interact(pPlayer, pHand);
if (ret.consumesAction()) return ret;

if(!pHand.equals(InteractionHand.MAIN_HAND)){
return InteractionResult.PASS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected boolean tickFuel() {


@Override
public ItemStack getPickResult() {
public @NotNull ItemStack getPickResult() {
return new ItemStack(ModItems.ENERGY_LOCOMOTIVE.get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public SteamLocomotiveEntity(Level level, Double x, Double y, Double z) {


@Override
public ItemStack getPickResult() {
public @NotNull ItemStack getPickResult() {
return new ItemStack(ModItems.STEAM_LOCOMOTIVE.get());
}

Expand Down
Loading

0 comments on commit da11abe

Please sign in to comment.