2018-12-20 00:39:10 +00:00
|
|
|
package net.shadowfacts.simplemultipart.multipart;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableList;
|
2018-12-20 01:44:53 +00:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2018-12-20 00:39:10 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.server.world.ServerWorld;
|
|
|
|
import net.minecraft.state.StateFactory;
|
2018-12-20 01:44:53 +00:00
|
|
|
import net.minecraft.util.Hand;
|
2018-12-20 00:39:10 +00:00
|
|
|
import net.minecraft.util.Identifier;
|
|
|
|
import net.minecraft.util.shape.VoxelShape;
|
|
|
|
import net.minecraft.world.loot.LootSupplier;
|
|
|
|
import net.minecraft.world.loot.LootTables;
|
|
|
|
import net.minecraft.world.loot.context.LootContext;
|
|
|
|
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
2018-12-24 22:16:38 +00:00
|
|
|
import net.shadowfacts.simplemultipart.util.MultipartPlacementContext;
|
2018-12-25 15:20:44 +00:00
|
|
|
import net.shadowfacts.simplemultipart.api.MultipartView;
|
2018-12-20 00:39:10 +00:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
public abstract class Multipart {
|
|
|
|
|
|
|
|
private StateFactory<Multipart, MultipartState> stateFactory;
|
|
|
|
private MultipartState defaultState;
|
|
|
|
|
|
|
|
private Identifier dropTableId;
|
|
|
|
|
|
|
|
public Multipart() {
|
|
|
|
StateFactory.Builder<Multipart, MultipartState> builder = new StateFactory.Builder<>(this);
|
|
|
|
appendProperties(builder);
|
|
|
|
stateFactory = builder.build(MultipartState::new);
|
|
|
|
defaultState = stateFactory.getDefaultState();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void appendProperties(StateFactory.Builder<Multipart, MultipartState> builder) {}
|
|
|
|
|
|
|
|
public MultipartState getDefaultState() {
|
|
|
|
return defaultState;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDefaultState(MultipartState defaultState) {
|
|
|
|
this.defaultState = defaultState;
|
|
|
|
}
|
|
|
|
|
|
|
|
public StateFactory<Multipart, MultipartState> getStateFactory() {
|
|
|
|
return stateFactory;
|
|
|
|
}
|
|
|
|
|
2018-12-24 22:16:38 +00:00
|
|
|
public MultipartState getPlacementState(MultipartPlacementContext context) {
|
2018-12-20 00:39:10 +00:00
|
|
|
return getDefaultState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can be overridden, should only be called via {@link MultipartState#getStateForRendering}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2018-12-25 15:20:44 +00:00
|
|
|
public MultipartState getStateForRendering(MultipartState state, MultipartView view) {
|
2018-12-20 00:39:10 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can be overridden, should only be called via {@link MultipartState#getBoundingShape}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2018-12-25 15:20:44 +00:00
|
|
|
public abstract VoxelShape getBoundingShape(/*@Nullable*/ MultipartState state, MultipartView view);
|
2018-12-20 00:39:10 +00:00
|
|
|
|
|
|
|
public Identifier getDropTableId() {
|
|
|
|
if (dropTableId == null) {
|
|
|
|
Identifier id = SimpleMultipart.MULTIPART.getId(this);
|
|
|
|
dropTableId = new Identifier(id.getNamespace(), "multiparts/" + id.getPath());
|
|
|
|
}
|
|
|
|
return dropTableId;
|
|
|
|
}
|
|
|
|
|
2018-12-20 01:44:53 +00:00
|
|
|
/**
|
|
|
|
* Can be overridden, should only be called via {@link MultipartState#getDroppedStacks)}
|
|
|
|
*/
|
2018-12-20 00:39:10 +00:00
|
|
|
@Deprecated
|
2018-12-25 15:20:44 +00:00
|
|
|
public List<ItemStack> getDroppedStacks(MultipartState state, MultipartView view, LootContext.Builder builder) {
|
2018-12-20 00:39:10 +00:00
|
|
|
Identifier dropTableId = getDropTableId();
|
|
|
|
if (dropTableId == LootTables.EMPTY) {
|
|
|
|
return ImmutableList.of();
|
|
|
|
} else {
|
|
|
|
LootContext context = builder.put(SimpleMultipart.MULTIPART_STATE_PARAMETER, state).build(SimpleMultipart.MULTIPART_LOOT_CONTEXT);
|
|
|
|
ServerWorld world = context.getWorld();
|
|
|
|
LootSupplier supplier = world.getServer().getLootManager().getSupplier(dropTableId);
|
|
|
|
return supplier.getDrops(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 01:44:53 +00:00
|
|
|
/**
|
|
|
|
* Can be overridden, should only be called via {@link MultipartState#activate}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2018-12-25 15:20:44 +00:00
|
|
|
public boolean activate(MultipartState state, MultipartView view, PlayerEntity player, Hand hand) {
|
2018-12-20 01:44:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-20 00:39:10 +00:00
|
|
|
}
|